agora inbox for [email protected]help / color / mirror / Atom feed
Re: POC: Cleaning up orphaned files using undo logs 811+ messages / 2 participants [nested] [flat]
* Re: POC: Cleaning up orphaned files using undo logs @ 2019-08-09 08:21 Amit Kapila <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Amit Kapila @ 2019-08-09 08:21 UTC (permalink / raw) To: Dilip Kumar <[email protected]>; +Cc: Thomas Munro <[email protected]>; Robert Haas <[email protected]>; Andres Freund <[email protected]>; Dmitry Dolgov <[email protected]>; Kuntal Ghosh <[email protected]>; pgsql-hackers On Mon, Jul 22, 2019 at 3:51 PM Dilip Kumar <[email protected]> wrote: > > On Mon, Jul 22, 2019 at 2:21 PM Amit Kapila <[email protected]> wrote: > > > > I have reviewed 0012-Infrastructure-to-execute-pending-undo-actions, > Please find my comment so far. > > 1. > + /* It shouldn't be discarded. */ > + Assert(!UndoRecPtrIsDiscarded(xact_urp)); > > I think comments can be added to explain why it shouldn't be discarded. > > 2. > + /* Compute the offset of the uur_next in the undo record. */ > + offset = SizeOfUndoRecordHeader + > + offsetof(UndoRecordTransaction, urec_progress); > + > in comment /uur_next/uur_progress > > 3. > +/* > + * undo_record_comparator > + * > + * qsort comparator to handle undo record for applying undo actions of the > + * transaction. > + */ > Function header formating is not in sync with other functions. > Fixed all the above comments in the attached patch. > 4. > +void > +undoaction_redo(XLogReaderState *record) > +{ > + uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK; > + > + switch (info) > + { > + case XLOG_UNDO_APPLY_PROGRESS: > + undo_xlog_apply_progress(record); > + break; > > For HotStandby it doesn't make sense to apply this wal as this > progress is only required when we try to apply the undo action after > restart > but in HotStandby we never apply undo actions. > I have already responded in my earlier email on why this is required [1]. > 5. > + Assert(from_urecptr != InvalidUndoRecPtr); > + Assert(to_urecptr != InvalidUndoRecPtr); > > we can use macros UndoRecPtrIsValid instead of checking like this. > Fixed. > 6. > + if ((slot == NULL) || (UndoRecPtrGetLogNo(urecptr) != slot->logno)) > + slot = UndoLogGetSlot(UndoRecPtrGetLogNo(urecptr), false); > + > + Assert(slot != NULL); > We are passing missing_ok as false in UndoLogGetSlot. But, not sure > why we are expecting that undo lot can not be dropped. In multi-log > transaction it's possible > that the tablespace in which next undolog is there is already dropped? > Already responded on this in my earlier reply [1]. > 7. > + */ > + do > + { > + BlockNumber progress_block_num = InvalidBlockNumber; > + int i; > + int nrecords; > ..... > + */ > + if (!UndoRecPtrIsValid(urec_ptr)) > + break; > + } while (true); > > I think we can convert above loop to while(true) instead of do..while, > because there is no need for do while loop. > > 8. > + if (last_urecinfo->uur->uur_info & UREC_INFO_LOGSWITCH) > + { > + UndoRecordLogSwitch *logswitch = last_urecinfo->uur->uur_logswitch; > > IMHO, the caller of UndoFetchRecord should directly check > uur->uur_logswitch instead of uur_info & UREC_INFO_LOGSWITCH. > Actually, uur_info is internally set > for inserting the tuple and check there to know what to insert and > fetch but I think caller of UndoFetchRecord should directly rely on > the field because ideally all > the fields in UnpackUndoRecord must be set and uur_txt or > uur_logswitch will be allocated when those headers present. I think > this needs to be improved in undo interface patch > as well (in UndoBulkFetchRecord). > Okay, fixed both of the above. I have exposed a new macro IsUndoLogSwitched from undorecord.h which you might also want to use in your patch. Apart from this, in the attached patches, I have fixed various comments raised in this thread from Amit Khandekar. I'll respond to them separately. I have yet to address various comments raised by Andres and Robert which also includes integration with the latest patch on queues posted by Robert. Note - The patches for undo-log and undo-interface has not been rebased as others are working actively on their branches. The branch where this code resides can be accessed at https://github.com/EnterpriseDB/zheap/tree/undoprocessing [1] - https://www.postgresql.org/message-id/CAA4eK1KoA0L%3DPNBc_uu2v8H0%3DLA_Cm%3Do9GyFm6i6DSD6mUMppg%40ma... -- With Regards, Amit Kapila. EnterpriseDB: http://www.enterprisedb.com Attachments: [application/octet-stream] 0001-Move-some-md.c-specific-logic-from-smgr.c-to-md.c.patch (7.7K, ../../CAA4eK1+McY0qGaak0AHyzdgAn+F6dyxcpDwp9ifGg=1WVDadeQ@mail.gmail.com/2-0001-Move-some-md.c-specific-logic-from-smgr.c-to-md.c.patch) download | inline diff: From dfd0121dc73aab491bcaad2d2b7a2a749389add8 Mon Sep 17 00:00:00 2001 From: Thomas Munro <[email protected]> Date: Wed, 17 Jul 2019 12:14:08 +1200 Subject: [PATCH 01/13] Move some md.c-specific logic from smgr.c to md.c. Potential future SMGR implementations may not want to create tablespace directories when creating an SMGR relation. Move that logic to mdcreate(). Move the initialization of md-specific data structures from smgropen() to a new callback mdopen(). Author: Thomas Munro Reviewed-by: Shawn Debnath (as part of an earlier patch set) Discussion: https://postgr.es/m/CA%2BhUKG%2BOZqOiOuDm5tC5DyQZtJ3FH4%2BFSVMqtdC4P1atpJ%2Bqhg%40mail.gmail.com --- src/backend/storage/smgr/md.c | 37 +++++++++++++++++++++++++++++++------ src/backend/storage/smgr/smgr.c | 33 ++++----------------------------- src/include/storage/md.h | 1 + 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c index 58c94e9..52136ad 100644 --- a/src/backend/storage/smgr/md.c +++ b/src/backend/storage/smgr/md.c @@ -28,6 +28,7 @@ #include "miscadmin.h" #include "access/xlogutils.h" #include "access/xlog.h" +#include "commands/tablespace.h" #include "pgstat.h" #include "postmaster/bgwriter.h" #include "storage/fd.h" @@ -120,7 +121,7 @@ static MemoryContext MdCxt; /* context for all MdfdVec objects */ /* local routines */ static void mdunlinkfork(RelFileNodeBackend rnode, ForkNumber forkNum, bool isRedo); -static MdfdVec *mdopen(SMgrRelation reln, ForkNumber forknum, int behavior); +static MdfdVec *mdopenfork(SMgrRelation reln, ForkNumber forknum, int behavior); static void register_dirty_segment(SMgrRelation reln, ForkNumber forknum, MdfdVec *seg); static void register_unlink_segment(RelFileNodeBackend rnode, ForkNumber forknum, @@ -165,7 +166,7 @@ mdexists(SMgrRelation reln, ForkNumber forkNum) */ mdclose(reln, forkNum); - return (mdopen(reln, forkNum, EXTENSION_RETURN_NULL) != NULL); + return (mdopenfork(reln, forkNum, EXTENSION_RETURN_NULL) != NULL); } /* @@ -185,6 +186,19 @@ mdcreate(SMgrRelation reln, ForkNumber forkNum, bool isRedo) Assert(reln->md_num_open_segs[forkNum] == 0); + /* + * We may be using the target table space for the first time in this + * database, so create a per-database subdirectory if needed. + * + * XXX this is a fairly ugly violation of module layering, but this seems + * to be the best place to put the check. Maybe TablespaceCreateDbspace + * should be here and not in commands/tablespace.c? But that would imply + * importing a lot of stuff that smgr.c oughtn't know, either. + */ + TablespaceCreateDbspace(reln->smgr_rnode.node.spcNode, + reln->smgr_rnode.node.dbNode, + isRedo); + path = relpath(reln->smgr_rnode, forkNum); fd = PathNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY); @@ -425,7 +439,7 @@ mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, } /* - * mdopen() -- Open the specified relation. + * mdopenfork() -- Open one fork of the specified relation. * * Note we only open the first segment, when there are multiple segments. * @@ -435,7 +449,7 @@ mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, * invent one out of whole cloth. */ static MdfdVec * -mdopen(SMgrRelation reln, ForkNumber forknum, int behavior) +mdopenfork(SMgrRelation reln, ForkNumber forknum, int behavior) { MdfdVec *mdfd; char *path; @@ -475,6 +489,17 @@ mdopen(SMgrRelation reln, ForkNumber forknum, int behavior) } /* + * mdopen() -- Initialize newly-opened relation. + */ +void +mdopen(SMgrRelation reln) +{ + /* mark it not open */ + for (int forknum = 0; forknum <= MAX_FORKNUM; forknum++) + reln->md_num_open_segs[forknum] = 0; +} + +/* * mdclose() -- Close the specified relation, if it isn't closed already. */ void @@ -713,7 +738,7 @@ mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber mdnblocks(SMgrRelation reln, ForkNumber forknum) { - MdfdVec *v = mdopen(reln, forknum, EXTENSION_FAIL); + MdfdVec *v = mdopenfork(reln, forknum, EXTENSION_FAIL); BlockNumber nblocks; BlockNumber segno = 0; @@ -1137,7 +1162,7 @@ _mdfd_getseg(SMgrRelation reln, ForkNumber forknum, BlockNumber blkno, v = &reln->md_seg_fds[forknum][reln->md_num_open_segs[forknum] - 1]; else { - v = mdopen(reln, forknum, behavior); + v = mdopenfork(reln, forknum, behavior); if (!v) return NULL; /* if behavior & EXTENSION_RETURN_NULL */ } diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c index dba8c39..b0d9f21 100644 --- a/src/backend/storage/smgr/smgr.c +++ b/src/backend/storage/smgr/smgr.c @@ -17,7 +17,6 @@ */ #include "postgres.h" -#include "commands/tablespace.h" #include "lib/ilist.h" #include "storage/bufmgr.h" #include "storage/ipc.h" @@ -41,6 +40,7 @@ typedef struct f_smgr { void (*smgr_init) (void); /* may be NULL */ void (*smgr_shutdown) (void); /* may be NULL */ + void (*smgr_open) (SMgrRelation reln); void (*smgr_close) (SMgrRelation reln, ForkNumber forknum); void (*smgr_create) (SMgrRelation reln, ForkNumber forknum, bool isRedo); @@ -68,6 +68,7 @@ static const f_smgr smgrsw[] = { { .smgr_init = mdinit, .smgr_shutdown = NULL, + .smgr_open = mdopen, .smgr_close = mdclose, .smgr_create = mdcreate, .smgr_exists = mdexists, @@ -170,8 +171,6 @@ smgropen(RelFileNode rnode, BackendId backend) /* Initialize it if not present before */ if (!found) { - int forknum; - /* hash_search already filled in the lookup key */ reln->smgr_owner = NULL; reln->smgr_targblock = InvalidBlockNumber; @@ -179,9 +178,8 @@ smgropen(RelFileNode rnode, BackendId backend) reln->smgr_vm_nblocks = InvalidBlockNumber; reln->smgr_which = 0; /* we only have md.c at present */ - /* mark it not open */ - for (forknum = 0; forknum <= MAX_FORKNUM; forknum++) - reln->md_num_open_segs[forknum] = 0; + /* implementation-specific initialization */ + smgrsw[reln->smgr_which].smgr_open(reln); /* it has no owner yet */ dlist_push_tail(&unowned_relns, &reln->node); @@ -330,33 +328,10 @@ smgrclosenode(RelFileNodeBackend rnode) * Given an already-created (but presumably unused) SMgrRelation, * cause the underlying disk file or other storage for the fork * to be created. - * - * If isRedo is true, it is okay for the underlying file to exist - * already because we are in a WAL replay sequence. */ void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo) { - /* - * Exit quickly in WAL replay mode if we've already opened the file. If - * it's open, it surely must exist. - */ - if (isRedo && reln->md_num_open_segs[forknum] > 0) - return; - - /* - * We may be using the target table space for the first time in this - * database, so create a per-database subdirectory if needed. - * - * XXX this is a fairly ugly violation of module layering, but this seems - * to be the best place to put the check. Maybe TablespaceCreateDbspace - * should be here and not in commands/tablespace.c? But that would imply - * importing a lot of stuff that smgr.c oughtn't know, either. - */ - TablespaceCreateDbspace(reln->smgr_rnode.node.spcNode, - reln->smgr_rnode.node.dbNode, - isRedo); - smgrsw[reln->smgr_which].smgr_create(reln, forknum, isRedo); } diff --git a/src/include/storage/md.h b/src/include/storage/md.h index df24b93..c0f05e2 100644 --- a/src/include/storage/md.h +++ b/src/include/storage/md.h @@ -21,6 +21,7 @@ /* md storage manager functionality */ extern void mdinit(void); +extern void mdopen(SMgrRelation reln); extern void mdclose(SMgrRelation reln, ForkNumber forknum); extern void mdcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo); extern bool mdexists(SMgrRelation reln, ForkNumber forknum); -- 1.8.3.1 [application/octet-stream] 0002-Prepare-to-support-multiple-SMGR-implementations.patch (1.4K, ../../CAA4eK1+McY0qGaak0AHyzdgAn+F6dyxcpDwp9ifGg=1WVDadeQ@mail.gmail.com/3-0002-Prepare-to-support-multiple-SMGR-implementations.patch) download | inline diff: From e3f1fb93eb7a8c5fad276c7dd6d82087135ae015 Mon Sep 17 00:00:00 2001 From: Thomas Munro <[email protected]> Date: Wed, 17 Jul 2019 14:15:27 +1200 Subject: [PATCH 02/13] Prepare to support multiple SMGR implementations. Move the "which" decision into a function that later patches can add to. Author: Thomas Munro --- src/backend/storage/smgr/smgr.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c index b0d9f21..d00b275 100644 --- a/src/backend/storage/smgr/smgr.c +++ b/src/backend/storage/smgr/smgr.c @@ -97,6 +97,18 @@ static dlist_head unowned_relns; /* local function prototypes */ static void smgrshutdown(int code, Datum arg); +/* + * Which implementation should handle a given RelFileNode? + */ +static int +smgrwhich(RelFileNode rnode) +{ + switch (rnode.dbNode) + { + default: + return 0; /* md.c */ + } +} /* * smgrinit(), smgrshutdown() -- Initialize or shut down storage @@ -176,7 +188,7 @@ smgropen(RelFileNode rnode, BackendId backend) reln->smgr_targblock = InvalidBlockNumber; reln->smgr_fsm_nblocks = InvalidBlockNumber; reln->smgr_vm_nblocks = InvalidBlockNumber; - reln->smgr_which = 0; /* we only have md.c at present */ + reln->smgr_which = smgrwhich(rnode); /* implementation-specific initialization */ smgrsw[reln->smgr_which].smgr_open(reln); -- 1.8.3.1 [application/octet-stream] 0003-Add-undo-log-manager.patch (177.2K, ../../CAA4eK1+McY0qGaak0AHyzdgAn+F6dyxcpDwp9ifGg=1WVDadeQ@mail.gmail.com/4-0003-Add-undo-log-manager.patch) download | inline diff: From 3da534dc6c28b2b3127d7400ab524f12b9faa0ae Mon Sep 17 00:00:00 2001 From: Thomas Munro <[email protected]> Date: Wed, 6 Mar 2019 16:46:04 +1300 Subject: [PATCH 03/13] Add undo log manager. Add a new subsystem to manage undo logs. Undo logs allow data to be appended efficiently, like logs. They also allow data to be discarded efficiently from the other end, like a queue. Thirdly, they allow efficient buffered random access, like a relation. Undo logs physically consist of a set of 1MB segment files under $PGDATA/base/undo (or per-tablespace equivalent) that are created, deleted or renamed as required, similarly to the way that WAL segments are managed. Meta-data about the set of undo logs is stored in shared memory, and written to per-checkpoint files under $PGDATA/pg_undo. Provide access to the undo files managed by undolog.c through bufmgr.c. A new SMGR implementation allows bufmgr.c to access files created by undolog.c. Author: Thomas Munro, with contributions from Dilip Kumar, Rafia Sabih, Robert Haas and Amit Kapila Reviewed-by: Discussion: https://postgr.es/m/CAEepm%3D2EqROYJ_xYz4v5kfr4b0qw_Lq_6Pe8RTEC8rx3upWsSQ%40mail.gmail.com --- src/backend/access/Makefile | 2 +- src/backend/access/rmgrdesc/Makefile | 2 +- src/backend/access/rmgrdesc/undologdesc.c | 81 + src/backend/access/transam/rmgr.c | 1 + src/backend/access/transam/xlog.c | 5 + src/backend/access/transam/xlogutils.c | 70 +- src/backend/access/undo/Makefile | 17 + src/backend/access/undo/undolog.c | 2627 +++++++++++++++++++++++++++++ src/backend/bootstrap/bootstrap.c | 3 + src/backend/catalog/system_views.sql | 4 + src/backend/commands/tablespace.c | 23 + src/backend/postmaster/pgstat.c | 21 + src/backend/replication/basebackup.c | 18 +- src/backend/replication/logical/decode.c | 1 + src/backend/storage/buffer/bufmgr.c | 80 +- src/backend/storage/buffer/localbuf.c | 43 + src/backend/storage/file/fd.c | 3 +- src/backend/storage/ipc/ipci.c | 3 + src/backend/storage/lmgr/lwlock.c | 2 + src/backend/storage/lmgr/lwlocknames.txt | 1 + src/backend/storage/smgr/Makefile | 2 +- src/backend/storage/smgr/smgr.c | 23 + src/backend/storage/smgr/undofile.c | 422 +++++ src/backend/storage/sync/sync.c | 6 + src/backend/utils/init/postinit.c | 2 + src/backend/utils/misc/guc.c | 12 + src/bin/initdb/initdb.c | 2 + src/bin/pg_checksums/pg_checksums.c | 23 +- src/bin/pg_resetwal/pg_resetwal.c | 76 + src/bin/pg_upgrade/Makefile | 2 +- src/bin/pg_upgrade/check.c | 43 + src/bin/pg_upgrade/controldata.c | 25 + src/bin/pg_upgrade/exec.c | 4 + src/bin/pg_upgrade/pg_upgrade.c | 2 + src/bin/pg_upgrade/pg_upgrade.h | 5 + src/bin/pg_upgrade/undo.c | 292 ++++ src/bin/pg_waldump/rmgrdesc.c | 1 + src/include/access/rmgrlist.h | 1 + src/include/access/session.h | 7 + src/include/access/undolog.h | 489 ++++++ src/include/access/undolog_xlog.h | 62 + src/include/access/xlogutils.h | 14 + src/include/catalog/database_internal.h | 21 + src/include/catalog/pg_proc.dat | 7 + src/include/pgstat.h | 7 + src/include/storage/bufmgr.h | 14 +- src/include/storage/fd.h | 1 + src/include/storage/lwlock.h | 5 +- src/include/storage/smgr.h | 3 + src/include/storage/sync.h | 3 +- src/include/storage/undofile.h | 59 + src/include/utils/guc.h | 2 + src/test/regress/expected/rules.out | 10 + 53 files changed, 4613 insertions(+), 41 deletions(-) create mode 100644 src/backend/access/rmgrdesc/undologdesc.c create mode 100644 src/backend/access/undo/Makefile create mode 100644 src/backend/access/undo/undolog.c create mode 100644 src/backend/storage/smgr/undofile.c create mode 100644 src/bin/pg_upgrade/undo.c create mode 100644 src/include/access/undolog.h create mode 100644 src/include/access/undolog_xlog.h create mode 100644 src/include/catalog/database_internal.h create mode 100644 src/include/storage/undofile.h diff --git a/src/backend/access/Makefile b/src/backend/access/Makefile index 0880e0a..bf6d3fa 100644 --- a/src/backend/access/Makefile +++ b/src/backend/access/Makefile @@ -9,6 +9,6 @@ top_builddir = ../../.. include $(top_builddir)/src/Makefile.global SUBDIRS = brin common gin gist hash heap index nbtree rmgrdesc spgist \ - table tablesample transam + table tablesample transam undo include $(top_srcdir)/src/backend/common.mk diff --git a/src/backend/access/rmgrdesc/Makefile b/src/backend/access/rmgrdesc/Makefile index 5514db1..91ad1ef 100644 --- a/src/backend/access/rmgrdesc/Makefile +++ b/src/backend/access/rmgrdesc/Makefile @@ -11,6 +11,6 @@ include $(top_builddir)/src/Makefile.global OBJS = brindesc.o clogdesc.o committsdesc.o dbasedesc.o genericdesc.o \ gindesc.o gistdesc.o hashdesc.o heapdesc.o logicalmsgdesc.o \ mxactdesc.o nbtdesc.o relmapdesc.o replorigindesc.o seqdesc.o \ - smgrdesc.o spgdesc.o standbydesc.o tblspcdesc.o xactdesc.o xlogdesc.o + smgrdesc.o spgdesc.o standbydesc.o tblspcdesc.o undologdesc.o xactdesc.o xlogdesc.o include $(top_srcdir)/src/backend/common.mk diff --git a/src/backend/access/rmgrdesc/undologdesc.c b/src/backend/access/rmgrdesc/undologdesc.c new file mode 100644 index 0000000..f89fcb3 --- /dev/null +++ b/src/backend/access/rmgrdesc/undologdesc.c @@ -0,0 +1,81 @@ +/*------------------------------------------------------------------------- + * + * undologdesc.c + * rmgr descriptor routines for access/undo/undolog.c + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/backend/access/rmgrdesc/undologdesc.c + * + *------------------------------------------------------------------------- + */ +#include "postgres.h" + +#include "access/undolog.h" +#include "access/undolog_xlog.h" + +void +undolog_desc(StringInfo buf, XLogReaderState *record) +{ + char *rec = XLogRecGetData(record); + uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK; + + if (info == XLOG_UNDOLOG_CREATE) + { + xl_undolog_create *xlrec = (xl_undolog_create *) rec; + + appendStringInfo(buf, "logno %u", xlrec->logno); + } + else if (info == XLOG_UNDOLOG_EXTEND) + { + xl_undolog_extend *xlrec = (xl_undolog_extend *) rec; + + appendStringInfo(buf, "logno %u end " UndoLogOffsetFormat, + xlrec->logno, xlrec->end); + } + else if (info == XLOG_UNDOLOG_DISCARD) + { + xl_undolog_discard *xlrec = (xl_undolog_discard *) rec; + + appendStringInfo(buf, "logno %u discard " UndoLogOffsetFormat " end " + UndoLogOffsetFormat, + xlrec->logno, xlrec->discard, xlrec->end); + } + else if (info == XLOG_UNDOLOG_SWITCH) + { + xl_undolog_switch *xlrec = (xl_undolog_switch *) rec; + + appendStringInfo(buf, "logno %u start " UndoLogOffsetFormat " last " UndoLogOffsetFormat, + xlrec->logno, + xlrec->prevlog_xact_start, + xlrec->prevlog_last_urp); + } + +} + +const char * +undolog_identify(uint8 info) +{ + const char *id = NULL; + + switch (info & ~XLR_INFO_MASK) + { + case XLOG_UNDOLOG_CREATE: + id = "CREATE"; + break; + case XLOG_UNDOLOG_EXTEND: + id = "EXTEND"; + break; + case XLOG_UNDOLOG_DISCARD: + id = "DISCARD"; + break; + case XLOG_UNDOLOG_SWITCH: + id = "SWITCH"; + break; + } + + return id; +} diff --git a/src/backend/access/transam/rmgr.c b/src/backend/access/transam/rmgr.c index 9368b56..8b05374 100644 --- a/src/backend/access/transam/rmgr.c +++ b/src/backend/access/transam/rmgr.c @@ -18,6 +18,7 @@ #include "access/multixact.h" #include "access/nbtxlog.h" #include "access/spgxlog.h" +#include "access/undolog_xlog.h" #include "access/xact.h" #include "access/xlog_internal.h" #include "catalog/storage_xlog.h" diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index b6c9353..5dbe485 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -31,6 +31,7 @@ #include "access/transam.h" #include "access/tuptoaster.h" #include "access/twophase.h" +#include "access/undolog.h" #include "access/xact.h" #include "access/xlog_internal.h" #include "access/xloginsert.h" @@ -6710,6 +6711,9 @@ StartupXLOG(void) */ restoreTwoPhaseData(); + /* Recover undo log meta data corresponding to this checkpoint. */ + StartupUndoLogs(ControlFile->checkPointCopy.redo); + lastFullPageWrites = checkPoint.fullPageWrites; RedoRecPtr = XLogCtl->RedoRecPtr = XLogCtl->Insert.RedoRecPtr = checkPoint.redo; @@ -8977,6 +8981,7 @@ static void CheckPointGuts(XLogRecPtr checkPointRedo, int flags) { CheckPointCLOG(); + CheckPointUndoLogs(checkPointRedo, ControlFile->checkPointCopy.redo); CheckPointCommitTs(); CheckPointSUBTRANS(); CheckPointMultiXact(); diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c index 10a663b..c227c03 100644 --- a/src/backend/access/transam/xlogutils.c +++ b/src/backend/access/transam/xlogutils.c @@ -294,6 +294,65 @@ XLogReadBufferForRedo(XLogReaderState *record, uint8 block_id, } /* + * Find the block ID of the first block that matches the given rnode forknum + * and blockno. If blockno is InvalidBlockNumber, then match any block + * number. Return true if found. + */ +bool +XLogFindBlockId(XLogReaderState *record, + RelFileNode rnode, + ForkNumber forknum, + BlockNumber blockno, + uint8 *block_id) +{ + uint8 i; + + for (i = 0; i <= record->max_block_id; ++i) + { + DecodedBkpBlock *block = &record->blocks[i]; + + if (block->in_use && + RelFileNodeEquals(block->rnode, rnode) && + block->forknum == forknum && + (block->blkno == blockno || blockno == InvalidBlockNumber)) + { + *block_id = i; + return true; + } + } + + return false; +} + +/* + * If the caller doesn't know the the block_id, but does know the RelFileNode, + * forknum and block number, then we try to find it. + */ +XLogRedoAction +XLogReadBufferForRedoBlock(XLogReaderState *record, + RelFileNode rnode, + ForkNumber forknum, + BlockNumber blockno, + ReadBufferMode mode, + bool get_cleanup_lock, + Buffer *buf) +{ + uint8 block_id; + + if (XLogFindBlockId(record, rnode, forknum, blockno, &block_id)) + return XLogReadBufferForRedoExtended(record, + block_id, + mode, + get_cleanup_lock, + buf); + + elog(ERROR, "failed to find block reference rel %u/%u/%u, forknum = %u, block = %u", + rnode.spcNode, rnode.dbNode, rnode.relNode, forknum, blockno); + + return BLK_NOTFOUND; /* not reached */ +} + +/* * Pin and lock a buffer referenced by a WAL record, for the purpose of * re-initializing it. */ @@ -346,7 +405,8 @@ XLogReadBufferForRedoExtended(XLogReaderState *record, * Make sure that if the block is marked with WILL_INIT, the caller is * going to initialize it. And vice versa. */ - zeromode = (mode == RBM_ZERO_AND_LOCK || mode == RBM_ZERO_AND_CLEANUP_LOCK); + zeromode = (mode == RBM_ZERO || mode == RBM_ZERO_AND_LOCK || + mode == RBM_ZERO_AND_CLEANUP_LOCK); willinit = (record->blocks[block_id].flags & BKPBLOCK_WILL_INIT) != 0; if (willinit && !zeromode) elog(PANIC, "block with WILL_INIT flag in WAL record must be zeroed by redo routine"); @@ -462,7 +522,7 @@ XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum, { /* page exists in file */ buffer = ReadBufferWithoutRelcache(rnode, forknum, blkno, - mode, NULL); + mode, NULL, RELPERSISTENCE_PERMANENT); } else { @@ -487,7 +547,8 @@ XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum, ReleaseBuffer(buffer); } buffer = ReadBufferWithoutRelcache(rnode, forknum, - P_NEW, mode, NULL); + P_NEW, mode, NULL, + RELPERSISTENCE_PERMANENT); } while (BufferGetBlockNumber(buffer) < blkno); /* Handle the corner case that P_NEW returns non-consecutive pages */ @@ -497,7 +558,8 @@ XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum, LockBuffer(buffer, BUFFER_LOCK_UNLOCK); ReleaseBuffer(buffer); buffer = ReadBufferWithoutRelcache(rnode, forknum, blkno, - mode, NULL); + mode, NULL, + RELPERSISTENCE_PERMANENT); } } diff --git a/src/backend/access/undo/Makefile b/src/backend/access/undo/Makefile new file mode 100644 index 0000000..219c696 --- /dev/null +++ b/src/backend/access/undo/Makefile @@ -0,0 +1,17 @@ +#------------------------------------------------------------------------- +# +# Makefile-- +# Makefile for access/undo +# +# IDENTIFICATION +# src/backend/access/undo/Makefile +# +#------------------------------------------------------------------------- + +subdir = src/backend/access/undo +top_builddir = ../../../.. +include $(top_builddir)/src/Makefile.global + +OBJS = undolog.o + +include $(top_srcdir)/src/backend/common.mk diff --git a/src/backend/access/undo/undolog.c b/src/backend/access/undo/undolog.c new file mode 100644 index 0000000..f2e0272 --- /dev/null +++ b/src/backend/access/undo/undolog.c @@ -0,0 +1,2627 @@ +/*------------------------------------------------------------------------- + * + * undolog.c + * management of undo logs + * + * PostgreSQL undo log manager. This module is responsible for managing the + * lifecycle of undo logs and their segment files, associating undo logs with + * backends, and allocating space within undo logs. + * + * For the code that reads and writes blocks of data, see undofile.c. + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/backend/access/undo/undolog.c + * + *------------------------------------------------------------------------- + */ + +#include "postgres.h" + +#include "access/session.h" +#include "access/transam.h" +#include "access/undolog.h" +#include "access/undolog_xlog.h" +#include "access/xact.h" +#include "access/xlog.h" +#include "access/xlogreader.h" +#include "access/xlogutils.h" +#include "catalog/catalog.h" +#include "catalog/pg_tablespace.h" +#include "commands/tablespace.h" +#include "funcapi.h" +#include "miscadmin.h" +#include "nodes/execnodes.h" +#include "pgstat.h" +#include "storage/buf.h" +#include "storage/bufmgr.h" +#include "storage/fd.h" +#include "storage/ipc.h" +#include "storage/lwlock.h" +#include "storage/procarray.h" +#include "storage/shmem.h" +#include "storage/standby.h" +#include "storage/sync.h" +#include "storage/undofile.h" +#include "utils/builtins.h" +#include "utils/guc.h" +#include "utils/memutils.h" +#include "utils/varlena.h" + +#include <sys/stat.h> +#include <unistd.h> + +/* + * Main control structure for undo log management in shared memory. + * UndoLogSlot objects are arranged in a fixed-size array, with no particular + * ordering. + */ +typedef struct UndoLogSharedData +{ + UndoLogNumber free_lists[UndoLogCategories]; + UndoLogNumber low_logno; + UndoLogNumber next_logno; + UndoLogNumber nslots; + UndoLogSlot slots[FLEXIBLE_ARRAY_MEMBER]; +} UndoLogSharedData; + +/* The shared memory region that all backends are attach to. */ +UndoLogSharedData *UndoLogShared; + +undologtable_hash *undologtable_cache; + +/* GUC variables */ +char *undo_tablespaces = NULL; + +static UndoLogSlot *find_undo_log_slot(UndoLogNumber logno, bool locked); +static UndoLogSlot *allocate_undo_log_slot(void); +static void free_undo_log_slot(UndoLogSlot *log); +static void attach_undo_log(UndoLogCategory category, Oid tablespace); +static void detach_current_undo_log(UndoLogCategory category, bool full); +static void extend_undo_log(UndoLogNumber logno, UndoLogOffset new_end); +static void undo_log_before_exit(int code, Datum value); +static void forget_undo_buffers(int logno, UndoLogOffset old_discard, + UndoLogOffset new_discard, + bool drop_tail); +static bool choose_undo_tablespace(bool force_detach, Oid *oid); + +PG_FUNCTION_INFO_V1(pg_stat_get_undo_logs); + +/* + * How many undo logs can be active at a time? This creates a theoretical + * maximum amount of undo data that can exist, but if we set it to a multiple + * of the maximum number of backends it will be a very high limit. + * Alternative designs involving demand paging or dynamic shared memory could + * remove this limit but would be complicated. + */ +static inline size_t +UndoLogNumSlots(void) +{ + return MaxBackends * 4; +} + +/* + * Return the amount of traditional shmem required for undo log management. + */ +Size +UndoLogShmemSize(void) +{ + return sizeof(UndoLogSharedData) + + UndoLogNumSlots() * sizeof(UndoLogSlot); +} + +/* + * Initialize the undo log subsystem. Called in each backend. + */ +void +UndoLogShmemInit(void) +{ + bool found; + + UndoLogShared = (UndoLogSharedData *) + ShmemInitStruct("UndoLogShared", UndoLogShmemSize(), &found); + + /* The postmaster initialized the shared memory state. */ + if (!IsUnderPostmaster) + { + int i; + + Assert(!found); + + /* + * We start with no active undo logs. StartUpUndoLogs() will recreate + * the undo logs that were known at the last checkpoint. + */ + memset(UndoLogShared, 0, sizeof(*UndoLogShared)); + UndoLogShared->nslots = UndoLogNumSlots(); + for (i = 0; i < UndoLogCategories; ++i) + UndoLogShared->free_lists[i] = InvalidUndoLogNumber; + for (i = 0; i < UndoLogShared->nslots; ++i) + { + memset(&UndoLogShared->slots[i], 0, sizeof(UndoLogShared->slots[i])); + UndoLogShared->slots[i].logno = InvalidUndoLogNumber; + LWLockInitialize(&UndoLogShared->slots[i].mutex, + LWTRANCHE_UNDOLOG); + LWLockInitialize(&UndoLogShared->slots[i].discard_lock, + LWTRANCHE_UNDODISCARD); + } + } + else + Assert(found); + + /* All backends prepare their per-backend lookup table. */ + undologtable_cache = undologtable_create(TopMemoryContext, + UndoLogNumSlots(), + NULL); +} + +void +UndoLogInit(void) +{ + before_shmem_exit(undo_log_before_exit, 0); +} + +/* + * Figure out which directory holds an undo log based on tablespace. + */ +void +UndoLogDirectory(Oid tablespace, char *dir) +{ + if (tablespace == DEFAULTTABLESPACE_OID || + tablespace == InvalidOid) + snprintf(dir, MAXPGPATH, "base/undo"); + else + snprintf(dir, MAXPGPATH, "pg_tblspc/%u/%s/undo", + tablespace, TABLESPACE_VERSION_DIRECTORY); +} + +/* + * Compute the pathname to use for an undo log segment file. + */ +void +UndoLogSegmentPath(UndoLogNumber logno, int segno, Oid tablespace, char *path) +{ + char dir[MAXPGPATH]; + + /* Figure out which directory holds the segment, based on tablespace. */ + UndoLogDirectory(tablespace, dir); + + /* + * Build the path from log number and offset. The pathname is the + * UndoRecPtr of the first byte in the segment in hexadecimal, with a + * period inserted between the components. + */ + snprintf(path, MAXPGPATH, "%s/%06X.%010zX", dir, logno, + segno * UndoLogSegmentSize); +} + +/* + * Iterate through the set of currently active logs. Pass in NULL to get the + * first undo log. NULL indicates the end of the set of logs. The caller + * must lock the returned log before accessing its members, and must skip if + * logno is not valid. + */ +UndoLogSlot * +UndoLogNextSlot(UndoLogSlot *slot) +{ + LWLockAcquire(UndoLogLock, LW_SHARED); + for (;;) + { + /* Advance to the next log. */ + if (slot == NULL) + { + /* Start at the beginning. */ + slot = &UndoLogShared->slots[0]; + } + else if (++slot == &UndoLogShared->slots[UndoLogShared->nslots]) + { + /* Past the end. */ + slot = NULL; + break; + } + /* Have we found a slot with a valid log? */ + if (slot->logno != InvalidUndoLogNumber) + break; + } + LWLockRelease(UndoLogLock); + + /* XXX: erm, which lock should the caller hold!? */ + return slot; +} + +/* + * Check if an undo log position has been discarded. 'pointer' must be an + * undo log pointer that was allocated at some point in the past, otherwise + * the result is undefined. + */ +bool +UndoLogRecPtrIsDiscardedSlowPath(UndoRecPtr pointer) +{ + UndoLogNumber logno = UndoRecPtrGetLogNo(pointer); + UndoLogSlot *slot; + UndoRecPtr discard; + + slot = find_undo_log_slot(logno, false); + + if (slot == NULL) + { + /* + * If we couldn't find the undo log number, then it must be entirely + * discarded. Set this backend's recent_discard value to the highest + * possible value, so that all records appear to be discarded to the + * fast-path code. Technically this value is too low by 1, but + * assuming only pointers to records are tested, and no record can + * have size 1, this value suffices. + */ + discard = MakeUndoRecPtr(logno, UndoLogMaxSize - 1); + } + else + { + LWLockAcquire(&slot->mutex, LW_SHARED); + if (unlikely(logno != slot->logno)) + { + /* + * The undo log has been entirely discarded since we looked it up + * above, and the UndoLogSlot is now unused or being used for some + * other undo log. This is the same as not finding it. + */ + discard = MakeUndoRecPtr(logno, UndoLogMaxSize - 1); + } + else + discard = MakeUndoRecPtr(logno, slot->meta.discard); + LWLockRelease(&slot->mutex); + } + + /* + * Remember this discard pointer in this backend so that future lookups + * via UndoLogRecPtrIsDiscarded() have a chance of avoiding the slow path. + */ + UndoLogGetTableEntry(logno)->recent_discard = discard; + + return pointer < discard; +} + +/* + * Fetch the previous transaction's start undo record point. + */ +UndoRecPtr +UndoLogGetLastXactStartPoint(UndoLogNumber logno) +{ + UndoLogSlot *slot = find_undo_log_slot(logno, false); + uint64 last_xact_start = 0; + + if (unlikely(slot == NULL)) + return InvalidUndoRecPtr; + + LWLockAcquire(&slot->mutex, LW_SHARED); + /* TODO: review */ + last_xact_start = slot->meta.unlogged.last_xact_start; + LWLockRelease(&slot->mutex); + + if (last_xact_start == 0) + return InvalidUndoRecPtr; + + return MakeUndoRecPtr(logno, last_xact_start); +} + +/* + * Detach from the undo log we are currently attached to, returning it to the + * appropriate free list if it still has space. + */ +static void +detach_current_undo_log(UndoLogCategory category, bool full) +{ + UndoLogSlot *slot; + + slot = CurrentSession->attached_undo_slots[category]; + + Assert(slot != NULL); + + CurrentSession->attached_undo_slots[category] = NULL; + + LWLockAcquire(&slot->mutex, LW_EXCLUSIVE); + slot->pid = InvalidPid; + slot->meta.unlogged.xid = InvalidTransactionId; + if (full) + slot->meta.status = UNDO_LOG_STATUS_FULL; + LWLockRelease(&slot->mutex); + + /* Push back onto the appropriate free list, unless it's full. */ + if (!full) + { + LWLockAcquire(UndoLogLock, LW_EXCLUSIVE); + slot->next_free = UndoLogShared->free_lists[category]; + UndoLogShared->free_lists[category] = slot->logno; + LWLockRelease(UndoLogLock); + } +} + +/* + * Exit handler, detaching from all undo logs. + */ +static void +undo_log_before_exit(int code, Datum arg) +{ + int i; + + if (!CurrentSession) + return; + + for (i = 0; i < UndoLogCategories; ++i) + { + if (CurrentSession->attached_undo_slots[i] != NULL) + detach_current_undo_log(i, false); + } +} + +/* + * Create a new empty segment file on disk for the byte starting at 'end'. + */ +static void +allocate_empty_undo_segment(UndoLogNumber logno, Oid tablespace, + UndoLogOffset end) +{ + struct stat stat_buffer; + off_t size; + char path[MAXPGPATH]; + void *zeroes; + size_t nzeroes = 8192; + int fd; + + UndoLogSegmentPath(logno, end / UndoLogSegmentSize, tablespace, path); + + /* + * Create and fully allocate a new file. If we crashed and recovered + * then the file might already exist, so use flags that tolerate that. + * It's also possible that it exists but is too short, in which case + * we'll write the rest. We don't really care what's in the file, we + * just want to make sure that the filesystem has allocated physical + * blocks for it, so that non-COW filesystems will report ENOSPC now + * rather than later when the space is needed and we'll avoid creating + * files with holes. + */ + fd = OpenTransientFile(path, O_RDWR | O_CREAT | PG_BINARY); + if (fd < 0 && tablespace != 0) + { + char undo_path[MAXPGPATH]; + + /* Try creating the undo directory for this tablespace. */ + UndoLogDirectory(tablespace, undo_path); + if (mkdir(undo_path, S_IRWXU) != 0 && errno != EEXIST) + { + char *parentdir; + + if (errno != ENOENT || !InRecovery) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not create directory \"%s\": %m", + undo_path))); + + /* + * In recovery, it's possible that the tablespace directory + * doesn't exist because a later WAL record removed the whole + * tablespace. In that case we create a regular directory to + * stand in for it. This is similar to the logic in + * TablespaceCreateDbspace(). + */ + + /* create two parents up if not exist */ + parentdir = pstrdup(undo_path); + get_parent_directory(parentdir); + get_parent_directory(parentdir); + /* Can't create parent and it doesn't already exist? */ + if (mkdir(parentdir, S_IRWXU) < 0 && errno != EEXIST) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not create directory \"%s\": %m", + parentdir))); + pfree(parentdir); + + /* create one parent up if not exist */ + parentdir = pstrdup(undo_path); + get_parent_directory(parentdir); + /* Can't create parent and it doesn't already exist? */ + if (mkdir(parentdir, S_IRWXU) < 0 && errno != EEXIST) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not create directory \"%s\": %m", + parentdir))); + pfree(parentdir); + + if (mkdir(undo_path, S_IRWXU) != 0 && errno != EEXIST) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not create directory \"%s\": %m", + undo_path))); + } + + fd = OpenTransientFile(path, O_RDWR | O_CREAT | PG_BINARY); + } + if (fd < 0) + elog(ERROR, "could not create new file \"%s\": %m", path); + if (fstat(fd, &stat_buffer) < 0) + elog(ERROR, "could not stat \"%s\": %m", path); + size = stat_buffer.st_size; + + /* A buffer full of zeroes we'll use to fill up new segment files. */ + zeroes = palloc0(nzeroes); + + while (size < UndoLogSegmentSize) + { + ssize_t written; + + written = write(fd, zeroes, Min(nzeroes, UndoLogSegmentSize - size)); + if (written < 0) + elog(ERROR, "cannot initialize undo log segment file \"%s\": %m", + path); + size += written; + } + + /* Flush the contents of the file to disk before the next checkpoint. */ + undofile_request_sync(logno, end / UndoLogSegmentSize, tablespace); + + CloseTransientFile(fd); + + pfree(zeroes); + + elog(DEBUG1, "created undo segment \"%s\"", path); +} + +/* + * Create a new undo segment, when it is unexpectedly not present. + */ +void +UndoLogNewSegment(UndoLogNumber logno, Oid tablespace, int segno) +{ + Assert(InRecovery); + allocate_empty_undo_segment(logno, tablespace, segno * UndoLogSegmentSize); +} + +/* + * Create and zero-fill a new segment for a given undo log number. + */ +static void +extend_undo_log(UndoLogNumber logno, UndoLogOffset new_end) +{ + UndoLogSlot *slot; + size_t end; + + slot = find_undo_log_slot(logno, false); + + /* TODO review interlocking */ + + Assert(slot != NULL); + Assert(slot->meta.end % UndoLogSegmentSize == 0); + Assert(new_end % UndoLogSegmentSize == 0); + Assert(InRecovery || + CurrentSession->attached_undo_slots[slot->meta.category] == slot); + + /* + * Create all the segments needed to increase 'end' to the requested + * size. This is quite expensive, so we will try to avoid it completely + * by renaming files into place in UndoLogDiscard() instead. + */ + end = slot->meta.end; + while (end < new_end) + { + allocate_empty_undo_segment(logno, slot->meta.tablespace, end); + end += UndoLogSegmentSize; + } + + /* Flush the directory entries before next checkpoint. */ + undofile_request_sync_dir(slot->meta.tablespace); + + /* + * If we're not in recovery, we need to WAL-log the creation of the new + * file(s). We do that after the above filesystem modifications, in + * violation of the data-before-WAL rule as exempted by + * src/backend/access/transam/README. This means that it's possible for + * us to crash having made some or all of the filesystem changes but + * before WAL logging, but in that case we'll eventually try to create the + * same segment(s) again, which is tolerated. + */ + if (!InRecovery) + { + xl_undolog_extend xlrec; + XLogRecPtr ptr; + + xlrec.logno = logno; + xlrec.end = end; + + XLogBeginInsert(); + XLogRegisterData((char *) &xlrec, sizeof(xlrec)); + ptr = XLogInsert(RM_UNDOLOG_ID, XLOG_UNDOLOG_EXTEND); + XLogFlush(ptr); + } + + /* + * We didn't need to acquire the mutex to read 'end' above because only + * we write to it. But we need the mutex to update it, because the + * checkpointer might read it concurrently. + * + * XXX It's possible for meta.end to be higher already during + * recovery, because of the timing of a checkpoint; in that case we did + * nothing above and we shouldn't update shmem here. That interaction + * needs more analysis. + */ + LWLockAcquire(&slot->mutex, LW_EXCLUSIVE); + if (slot->meta.end < end) + slot->meta.end = end; + LWLockRelease(&slot->mutex); +} + +/* + * This function must be called before all of the undo log activity that will + * be covered by a single WAL record. + */ +void +UndoLogBeginInsert(UndoLogAllocContext *context, + UndoLogCategory category, + XLogReaderState *xlog_record) +{ + context->try_location = InvalidUndoRecPtr; + context->category = category; + + /* + * Tell UndoLogAllocate() to capture undo log meta-data before-change + * images, so that UndoLogRegister() can find them and they can be written + * to the WAL once per checkpoint. + */ + context->num_meta_data_images = 0; + + /* + * Tell UndoLogAllocateInRecovery() that we don't know which undo log to + * allocate in yet, and to start its search for registered blocks at + * the lowest-numbered block_id. + */ + context->xlog_record = xlog_record; + context->recovery_logno = InvalidUndoLogNumber; + context->recovery_block_id = 0; + + /* + * For UNDO_SHARED, this always denotes the beginning of a new record set. + * For other categories, the boundaries are detected by transaction ID + * changes. + */ + context->new_shared_record_set = category == UNDO_SHARED; +} + +/* + * Get an insertion point that is guaranteed to be backed by enough space to + * hold 'size' bytes of data. To actually write into the undo log, client + * code should call this first and then use bufmgr routines to access buffers + * and provide WAL logs and redo handlers. In other words, while this module + * looks after making sure the undo log has sufficient space and the undo meta + * data is crash safe, the *contents* of the undo log and (indirectly) the + * insertion point are the responsibility of client code. + * + * A suggested insertion point can optionally be passed in as 'try_location', + * and will be returned if possible. If not InvalidUndoRecPtr, it must fall + * with, or exactly one byte after, the most recent allocation for the same + * persistence level. This interface allows for a series of allocation to be + * made without committing to using the space yet; call UndoLogAdvance() to + * actually advance the insert pointer. + * + * Return an undo log insertion point that can be converted to a buffer tag + * and an insertion point within a buffer page. + */ +UndoRecPtr +UndoLogAllocate(UndoLogAllocContext *context, + uint16 size, + bool *need_xact_header, + UndoRecPtr *last_xact_start, + UndoRecPtr *prevlog_xact_start, + UndoRecPtr *prevlog_insert_urp) +{ + Session *session = CurrentSession; + UndoLogSlot *slot; + UndoLogOffset new_insert; + TransactionId logxid; + + slot = CurrentSession->attached_undo_slots[context->category]; + + /* + * We may need to attach to an undo log, either because this is the first + * time this backend as needed to write to an undo log at all or because + * the undo_tablespaces GUC was changed. When doing that, we'll need + * interlocking against tablespaces being concurrently dropped. + */ + + retry: + /* See if we need to check the undo_tablespaces GUC. */ + if (unlikely(session->need_to_choose_undo_tablespace || slot == NULL)) + { + Oid tablespace; + bool need_to_unlock; + + need_to_unlock = + choose_undo_tablespace(session->need_to_choose_undo_tablespace, + &tablespace); + attach_undo_log(context->category, tablespace); + if (need_to_unlock) + LWLockRelease(TablespaceCreateLock); + slot = CurrentSession->attached_undo_slots[context->category]; + session->need_to_choose_undo_tablespace = false; + } + + LWLockAcquire(&slot->mutex, LW_EXCLUSIVE); + logxid = slot->meta.unlogged.xid; + + if (logxid != GetTopTransactionId()) + { + /* + * While we have the lock, check if we have been forcibly detached by + * DROP TABLESPACE. That can only happen between transactions (see + * DropUndoLogsInsTablespace()). + */ + if (slot->pid == InvalidPid) + { + LWLockRelease(&slot->mutex); + slot = NULL; + goto retry; + } + /* Record that we are attached to this log. */ + slot->meta.unlogged.xid = GetTopTransactionId(); + /* + * Maintain our tracking of the and the previous transaction start + * locations. + */ + if (slot->meta.unlogged.this_xact_start != slot->meta.unlogged.insert) + { + slot->meta.unlogged.last_xact_start = + slot->meta.unlogged.this_xact_start; + slot->meta.unlogged.this_xact_start = slot->meta.unlogged.insert; + } + } + LWLockRelease(&slot->mutex); + + /* + * 'size' is expressed in usable non-header bytes. Figure out how far we + * have to move insert to create space for 'size' usable bytes, stepping + * over any intervening headers. + */ + Assert(slot->meta.unlogged.insert % BLCKSZ >= UndoLogBlockHeaderSize); + if (context->try_location != InvalidUndoRecPtr) + { + /* + * The try location must be in the log we're attached to, at most one + * byte past the end of space backed by files. + */ + UndoLogOffset try_offset = UndoRecPtrGetOffset(context->try_location); + + Assert(UndoRecPtrGetLogNo(context->try_location) == slot->logno); + Assert(try_offset <= slot->meta.end); + new_insert = UndoLogOffsetPlusUsableBytes(try_offset, size); + } + else + { + new_insert = UndoLogOffsetPlusUsableBytes(slot->meta.unlogged.insert, + size); + } + Assert(new_insert % BLCKSZ >= UndoLogBlockHeaderSize); + + /* + * We don't need to acquire log->mutex to read log->meta.insert and + * log->meta.end, because this backend is the only one that can + * modify them. + */ + if (unlikely(new_insert > slot->meta.end)) + { + if (new_insert > UndoLogMaxSize) + { + /* This undo log is entirely full. Get a new one. */ + if (logxid == GetTopTransactionId()) + { + /* + * If the same transaction is split over two undo logs then + * store the previous log number in new log. See detailed + * comments in undorecord.c file header. + */ + *prevlog_xact_start = + MakeUndoRecPtr(slot->logno, + slot->meta.unlogged.this_xact_start); + *prevlog_insert_urp = + MakeUndoRecPtr(slot->logno, slot->meta.unlogged.insert); + } + elog(DEBUG1, "undo log %u is full, switching to a new one", slot->logno); + slot = NULL; + detach_current_undo_log(context->category, true); + context->try_location = InvalidUndoRecPtr; + goto retry; + } + /* + * Extend the end of this undo log to cover new_insert (in other words + * round up to the segment size). + */ + extend_undo_log(slot->logno, + new_insert + UndoLogSegmentSize - + new_insert % UndoLogSegmentSize); + Assert(new_insert <= slot->meta.end); + } + + /* + * Create a back-up image of the unlogged part of the undo log's + * meta-data, if we haven't already done so since UndoLogBeginInsert() (ie + * for the WAL record that this undo allocation will be replayed by). + */ + if (context->num_meta_data_images == 0 || + context->meta_data_images[context->num_meta_data_images - 1].logno != slot->logno) + { + if (context->num_meta_data_images >= MAX_META_DATA_IMAGES) + elog(ERROR, "too many undo log meta data images"); + context->meta_data_images[context->num_meta_data_images].logno = slot->logno; + context->meta_data_images[context->num_meta_data_images++].data = slot->meta.unlogged; + } + + /* + * If no try_location was passed in, or if we switched logs, then we'll + * return the current insertion point. + */ + if (context->try_location == InvalidUndoRecPtr) + context->try_location = MakeUndoRecPtr(slot->logno, slot->meta.unlogged.insert); + + /* + * Is this location the first in this undo log for a transaction or a + * shared record set? + */ + if (context->new_shared_record_set) + { + context->new_shared_record_set = false; + *need_xact_header = true; + } + else + { + *need_xact_header = + UndoRecPtrGetOffset(context->try_location) == + slot->meta.unlogged.this_xact_start; + } + *last_xact_start = + MakeUndoRecPtr(slot->logno, slot->meta.unlogged.last_xact_start); + + return context->try_location; +} + +void +UndoLogRegister(UndoLogAllocContext *context, uint8 block_id, UndoLogNumber logno) +{ + int i; + + for (i = 0; i < context->num_meta_data_images; ++i) + { + if (context->meta_data_images[i].logno == logno) + { + XLogRegisterBufData(block_id, + (char *) &context->meta_data_images[i].data, + sizeof(context->meta_data_images[i].data)); + return; + } + } +} + +/* + * In recovery, we expect exactly the same sequence of allocation sizes, but + * we also need the WAL record that is being replayed so we can figure out + * where the undo space was allocated. + */ +UndoRecPtr +UndoLogAllocateInRecovery(UndoLogAllocContext *context, + TransactionId xid, + uint16 size, + bool *need_xact_header, + UndoRecPtr *last_xact_start, + UndoRecPtr *prevlog_xact_start, + UndoRecPtr *prevlog_last_urp) +{ + UndoLogSlot *slot; + + Assert(InRecovery); + + /* + * Just as in UndoLogAllocate(), the caller may be extending an existing + * allocation before committing with UndoLogAdvance(). + */ + if (context->try_location != InvalidUndoRecPtr) + { + /* + * The try location must be in the log we're attached to, at most one + * byte past the end of space backed by files. + */ + UndoLogOffset try_offset = UndoRecPtrGetOffset(context->try_location); + UndoLogNumber logno = UndoRecPtrGetLogNo(context->try_location); + + /* + * You can only have a try_location on your second or later allocation + * for a given WAL record. It had better be in the same log as the + * previous allocation for this WAL record (though it may not turn out + * to have enough space, below). + */ + Assert(logno == context->recovery_logno); + + /* + * Any log extension triggered by UndoLogAllocate() must have been + * replayed by now, so we can just check if this log has enough space, + * and if so, return. + */ + slot = find_undo_log_slot(logno, false); + if (UndoLogOffsetPlusUsableBytes(try_offset, size) <= slot->meta.end) + { + *need_xact_header = false; + return try_offset; + } + + /* Full. Ignore try_location and find the next log that was used. */ + Assert(slot->meta.status == UNDO_LOG_STATUS_FULL); + } + else + { + /* + * For now we only support one allocation per WAL record that doesn't + * have a try_location (ie the first one). We'll have to find out + * which log was used first. + */ + Assert(context->recovery_logno == InvalidUndoLogNumber); + } + + /* + * In order to find the undo log that was used by UndoLogAllocate(), we + * consult the list of registered blocks to figure out which undo logs + * should be written to by this WAL record. + */ + while (context->recovery_block_id <= context->xlog_record->max_block_id) + { + DecodedBkpBlock *block; + + /* We're looking for the first block referencing a new undo log. */ + block = &context->xlog_record->blocks[context->recovery_block_id]; + if (block->rnode.dbNode == UndoDbOid && + block->rnode.relNode != context->recovery_logno) + { + UndoLogNumber logno = block->rnode.relNode; + const void *backup; + size_t backup_size; + + /* We found a reference to a different (or first) undo log. */ + slot = find_undo_log_slot(logno, false); + + /* + * Since on-line checkpoints capture an inconsistent snapshot of + * undo log meta-data, we'll restore the unlogged part of the + * meta-data image if one was attached to the WAL record (that is, + * the members that don't have WAL records for every change + * already). + */ + backup = + XLogRecGetBlockData(context->xlog_record, + context->recovery_block_id, + &backup_size); + if (unlikely(backup)) + { + Assert(backup_size == sizeof(UndoLogUnloggedMetaData)); + + /* Restore the unlogged members from the backup-imaged. */ + LWLockAcquire(&slot->mutex, LW_EXCLUSIVE); + memcpy(&slot->meta.unlogged, backup, sizeof(UndoLogUnloggedMetaData)); + LWLockRelease(&slot->mutex); + } + else + { + /* + * Otherwise we need to do our own transaction tracking + * whenever we see a new xid, to match the logic in + * UndoLogAllocate(). + */ + if (xid != slot->meta.unlogged.xid) + { + slot->meta.unlogged.xid = xid; + if (slot->meta.unlogged.this_xact_start != slot->meta.unlogged.insert) + slot->meta.unlogged.last_xact_start = + slot->meta.unlogged.this_xact_start; + slot->meta.unlogged.this_xact_start = + slot->meta.unlogged.insert; + } + } + + /* TODO: check locking against undo log slot recycling? */ + + /* + * At this stage we should have an undo log that can handle this + * allocation. If we don't, something is screwed up. + */ + if (UndoLogOffsetPlusUsableBytes(slot->meta.unlogged.insert, size) > slot->meta.end) + elog(ERROR, + "cannot allocate %d bytes in undo log %d", + (int) size, slot->logno); + + *need_xact_header = + context->try_location == InvalidUndoRecPtr && + slot->meta.unlogged.insert == slot->meta.unlogged.this_xact_start; + *last_xact_start = slot->meta.unlogged.last_xact_start; + context->recovery_logno = slot->logno; + + /* Read log switch information from meta and reset it. */ + *prevlog_xact_start = slot->meta.unlogged.prevlog_xact_start; + *prevlog_last_urp = slot->meta.unlogged.prevlog_last_urp; + + slot->meta.unlogged.prevlog_xact_start = InvalidUndoRecPtr; + slot->meta.unlogged.prevlog_last_urp = InvalidUndoRecPtr; + + return MakeUndoRecPtr(slot->logno, slot->meta.unlogged.insert); + } + ++context->recovery_block_id; + } + + /* + * If we've run out of blocks to inspect, then we must have replayed a + * different sequence of allocation sizes, or screwed up the + * XLOG_UNDOLOG_EXTEND records, indicating a bug somewhere. + */ + elog(ERROR, "cannot determine undo log to allocate from"); + + return 0; /* not reached */ +} + +/* + * Advance the insertion pointer in this context by 'size' usable (non-header) + * bytes. This is the next place we'll try to allocate a record, if it fits. + * This is not committed to shared memory until after we've WAL-logged the + * record and UndoLogAdvanceFinal() is called. + */ +void +UndoLogAdvance(UndoLogAllocContext *context, size_t size) +{ + context->try_location = UndoLogOffsetPlusUsableBytes(context->try_location, + size); +} + +/* + * Advance the insertion pointer to 'size' usable (non-header) bytes past + * insertion_point. + */ +void +UndoLogAdvanceFinal(UndoRecPtr insertion_point, size_t size) +{ + UndoLogSlot *slot = NULL; + UndoLogNumber logno = UndoRecPtrGetLogNo(insertion_point) ; + + slot = find_undo_log_slot(logno, false); + + /* + * Either we're in recovery, or is a log we are currently attached to, or + * recently detached from because it was full. + */ + Assert(InRecovery || + AmAttachedToUndoLogSlot(slot) || + slot->meta.status == UNDO_LOG_STATUS_FULL); + + /* + * The caller has the current insertion point, as returned by + * UndoLogAllocate[InRecovery](). + */ + Assert(UndoRecPtrGetOffset(insertion_point) == slot->meta.unlogged.insert); + + LWLockAcquire(&slot->mutex, LW_EXCLUSIVE); + slot->meta.unlogged.insert = + UndoLogOffsetPlusUsableBytes(slot->meta.unlogged.insert, size); + LWLockRelease(&slot->mutex); +} + +/* + * Advance the discard pointer in one undo log, discarding all undo data + * relating to one or more whole transactions. The passed in undo pointer is + * the address of the oldest data that the called would like to keep, and the + * affected undo log is implied by this pointer, ie + * UndoRecPtrGetLogNo(discard_pointer). + * + * The caller asserts that there will be no attempts to access the undo log + * region being discarded after this moment. This operation will cause the + * relevant buffers to be dropped immediately, without writing any data out to + * disk. Any attempt to read the buffers (except a partial buffer at the end + * of this range which will remain) may result in IO errors, because the + * underlying segment file may have been physically removed. + * + * Return true if the discard point was updated, and false if nothing was done + * because the log precending the given point was already discarded. + * + * TODO: The return value is not yet reliable and the code still doesn't work + * correctly if called for the same undo log in two backends; more + * interlocking work required here. + */ +bool +UndoLogDiscard(UndoRecPtr discard_point, TransactionId xid) +{ + UndoLogNumber logno = UndoRecPtrGetLogNo(discard_point); + UndoLogOffset discard = UndoRecPtrGetOffset(discard_point); + UndoLogOffset old_discard; + UndoLogOffset end; + UndoLogSlot *slot; + int segno; + int new_segno; + bool need_to_flush_wal = false; + bool entirely_discarded = false; + + slot = find_undo_log_slot(logno, false); + if (unlikely(slot == NULL)) + { + /* Already discarded (entirely). */ + return false; + } + + LWLockAcquire(&slot->mutex, LW_EXCLUSIVE); + if (unlikely(slot->logno != logno || discard <= slot->meta.discard)) + { + /* + * Already discarded entirely and the slot has been recycled, or up + * to this point). + */ + LWLockRelease(&slot->mutex); + return false; + } + if (discard > slot->meta.unlogged.insert) + elog(ERROR, "cannot move discard point past insert point"); + old_discard = slot->meta.discard; + end = slot->meta.end; + /* Are we discarding the last remaining data in a log marked as full? */ + if (slot->meta.status == UNDO_LOG_STATUS_FULL && + discard == slot->meta.unlogged.insert) + { + /* + * Adjust the discard and insert pointers so that the final segment is + * deleted from disk, and remember not to recycle it. + */ + entirely_discarded = true; + /* TODO: Check if the following line is replayed correctly */ + slot->meta.unlogged.insert = slot->meta.end; + discard = slot->meta.end; + } + LWLockRelease(&slot->mutex); + + /* + * TODO: I think we need a new lock just for this phase, so that buffer + * dropping and IO are done by only one backend if a superuser command and + * a discard worker both run this! + */ + + /* + * Drop all buffers holding this undo data out of the buffer pool (except + * the last one, if the new location is in the middle of it somewhere), so + * that the contained data doesn't ever touch the disk. The caller + * promises that this data will not be needed again. We have to drop the + * buffers from the buffer pool before removing files, otherwise a + * concurrent session might try to write the block to evict the buffer. + */ + forget_undo_buffers(logno, old_discard, discard, entirely_discarded); + + /* + * Check if we crossed a segment boundary and need to do some synchronous + * filesystem operations. + */ + segno = old_discard / UndoLogSegmentSize; + new_segno = discard / UndoLogSegmentSize; + if (segno < new_segno) + { + int recycle; + UndoLogOffset pointer; + + /* + * We always WAL-log discards, but we only need to flush the WAL if we + * have performed a filesystem operation. + */ + need_to_flush_wal = true; + + /* + * XXX When we rename or unlink a file, it's possible that some + * backend still has it open because it has recently read a page from + * it. smgr/undofile.c in any such backend will eventually close it, + * because it considers that fd to belong to the file with the name + * that we're unlinking or renaming and it doesn't like to keep more + * than one open at a time. No backend should ever try to read from + * such a file descriptor; that is what it means when we say that the + * caller of UndoLogDiscard() asserts that there will be no attempts + * to access the discarded range of undo log. In the case of a + * rename, if a backend were to attempt to read undo data in the range + * being discarded, it would read entirely the wrong data. + */ + + /* + * How many segments should we recycle (= rename from tail position to + * head position)? For now it's always 1 unless there is already a + * spare one, but we could have an adaptive algorithm that recycles + * multiple segments at a time and pays just one fsync(). + */ + LWLockAcquire(&slot->mutex, LW_SHARED); + if ((slot->meta.end - slot->meta.unlogged.insert) < UndoLogSegmentSize && + slot->meta.status == UNDO_LOG_STATUS_ACTIVE) + recycle = 1; + else + recycle = 0; + LWLockRelease(&slot->mutex); + + /* Rewind to the start of the segment. */ + pointer = segno * UndoLogSegmentSize; + + while (pointer < new_segno * UndoLogSegmentSize) + { + char discard_path[MAXPGPATH]; + + /* Tell the checkpointer that the file is going away. */ + undofile_forget_sync(logno, pointer / UndoLogSegmentSize, + slot->meta.tablespace); + + UndoLogSegmentPath(logno, pointer / UndoLogSegmentSize, + slot->meta.tablespace, discard_path); + + /* Can we recycle the oldest segment? */ + if (recycle > 0) + { + char recycle_path[MAXPGPATH]; + + /* + * End points one byte past the end of the current undo space, + * ie to the first byte of the segment file we want to create. + */ + UndoLogSegmentPath(logno, end / UndoLogSegmentSize, + slot->meta.tablespace, recycle_path); + if (rename(discard_path, recycle_path) == 0) + { + elog(DEBUG1, "recycled undo segment \"%s\" -> \"%s\"", + discard_path, recycle_path); + end += UndoLogSegmentSize; + --recycle; + } + else + { + elog(ERROR, "could not rename \"%s\" to \"%s\": %m", + discard_path, recycle_path); + } + } + else + { + if (unlink(discard_path) == 0) + elog(DEBUG1, "unlinked undo segment \"%s\"", discard_path); + else + elog(ERROR, "could not unlink \"%s\": %m", discard_path); + } + pointer += UndoLogSegmentSize; + } + } + + /* WAL log the discard. */ + { + xl_undolog_discard xlrec; + XLogRecPtr ptr; + + xlrec.logno = logno; + xlrec.discard = discard; + xlrec.end = end; + xlrec.latestxid = xid; + xlrec.entirely_discarded = entirely_discarded; + + XLogBeginInsert(); + XLogRegisterData((char *) &xlrec, sizeof(xlrec)); + ptr = XLogInsert(RM_UNDOLOG_ID, XLOG_UNDOLOG_DISCARD); + + if (need_to_flush_wal) + XLogFlush(ptr); + } + + /* Update shmem to show the new discard and end pointers. */ + LWLockAcquire(&slot->mutex, LW_EXCLUSIVE); + slot->meta.discard = discard; + slot->meta.end = end; + LWLockRelease(&slot->mutex); + + /* If we discarded everything, the slot can be given up. */ + if (entirely_discarded) + free_undo_log_slot(slot); + + return true; +} + +/* + * Return an UndoRecPtr to the oldest valid data in an undo log, or + * InvalidUndoRecPtr if it is empty. + */ +UndoRecPtr +UndoLogGetOldestRecord(UndoLogNumber logno, bool *full) +{ + UndoLogSlot *slot; + UndoRecPtr result; + + /* Try to find the slot for this undo log number. */ + slot = find_undo_log_slot(logno, false); + if (slot == NULL) + { + /* It's unknown to us, so we assume it's been entirely discarded. */ + if (full) + *full = true; + return InvalidUndoRecPtr; + } + + LWLockAcquire(&slot->mutex, LW_SHARED); + if (slot->logno != logno) + { + /* It's been recycled. SO it must have been entirely discarded. */ + result = InvalidUndoRecPtr; + if (full) + *full = true; + } + else if (slot->meta.discard == slot->meta.unlogged.insert) + { + /* It's empty, so there is no oldest record pointer to return. */ + result = InvalidUndoRecPtr; + if (full) + *full = slot->meta.status == UNDO_LOG_STATUS_FULL; + } + else + { + /* There is a record here! */ + result = MakeUndoRecPtr(slot->logno, slot->meta.discard); + if (full) + *full = slot->meta.status == UNDO_LOG_STATUS_FULL; + } + LWLockRelease(&slot->mutex); + + return result; +} + +/* + * UndoLogSwitchSetPrevLogInfo - Store previous log info on the log switch and + * wal log the same. + */ +void +UndoLogSwitchSetPrevLogInfo(UndoLogNumber logno, UndoRecPtr prevlog_xact_start, + UndoRecPtr prevlog_last_urp) +{ + UndoLogSlot *slot; + + slot = find_undo_log_slot(logno, false); + + /* + * Either we're in recovery, or is a log we are currently attached to, or + * recently detached from because it was full. + */ + Assert(AmAttachedToUndoLogSlot(slot)); + + LWLockAcquire(&slot->mutex, LW_EXCLUSIVE); + slot->meta.unlogged.prevlog_xact_start = prevlog_last_urp; + slot->meta.unlogged.prevlog_last_urp = prevlog_last_urp; + LWLockRelease(&slot->mutex); + + /* Wal log the log switch. */ + { + xl_undolog_switch xlrec; + + xlrec.logno = logno; + xlrec.prevlog_xact_start = prevlog_last_urp; + xlrec.prevlog_last_urp = prevlog_xact_start; + + XLogBeginInsert(); + XLogRegisterData((char *) &xlrec, sizeof(xlrec)); + XLogInsert(RM_UNDOLOG_ID, XLOG_UNDOLOG_SWITCH); + } +} + +/* + * Return the next insert location. + */ +UndoRecPtr +UndoLogGetNextInsertPtr(UndoLogNumber logno) +{ + UndoLogSlot *slot = find_undo_log_slot(logno, false); + UndoRecPtr insert; + + LWLockAcquire(&slot->mutex, LW_SHARED); + /* TODO: what if the slot has been recycled? */ + insert = slot->meta.unlogged.insert; + LWLockRelease(&slot->mutex); + + return MakeUndoRecPtr(logno, insert); +} + +/* + * Delete unreachable files under pg_undo. Any files corresponding to LSN + * positions before the previous checkpoint are no longer needed. + */ +static void +CleanUpUndoCheckPointFiles(XLogRecPtr checkPointRedo) +{ + DIR *dir; + struct dirent *de; + char path[MAXPGPATH]; + char oldest_path[MAXPGPATH]; + + /* + * If a base backup is in progress, we can't delete any checkpoint + * snapshot files because one of them corresponds to the backup label but + * there could be any number of checkpoints during the backup. + */ + if (BackupInProgress()) + return; + + /* Otherwise keep only those >= the previous checkpoint's redo point. */ + snprintf(oldest_path, MAXPGPATH, "%016" INT64_MODIFIER "X", + checkPointRedo); + dir = AllocateDir("pg_undo"); + while ((de = ReadDir(dir, "pg_undo")) != NULL) + { + /* + * Assume that fixed width uppercase hex strings sort the same way as + * the values they represent, so we can use strcmp to identify undo + * log snapshot files corresponding to checkpoints that we don't need + * anymore. This assumption holds for ASCII. + */ + if (!(strlen(de->d_name) == UNDO_CHECKPOINT_FILENAME_LENGTH)) + continue; + + if (UndoCheckPointFilenamePrecedes(de->d_name, oldest_path)) + { + snprintf(path, MAXPGPATH, "pg_undo/%s", de->d_name); + if (unlink(path) != 0) + elog(ERROR, "could not unlink file \"%s\": %m", path); + } + } + FreeDir(dir); +} + +/* + * Write out the undo log meta data to the pg_undo directory. The actual + * contents of undo logs is in shared buffers and therefore handled by + * CheckPointBuffers(), but here we record the table of undo logs and their + * properties. + */ +void +CheckPointUndoLogs(XLogRecPtr checkPointRedo, XLogRecPtr priorCheckPointRedo) +{ + UndoLogMetaData *serialized = NULL; + size_t serialized_size = 0; + char *data; + char path[MAXPGPATH]; + UndoLogNumber num_logs; + int fd; + int i; + pg_crc32c crc; + + /* + * We acquire UndoLogLock to prevent any undo logs from being created or + * discarded while we build a snapshot of them. This isn't expected to + * take long on a healthy system because the number of active logs should + * be around the number of backends. Holding this lock won't prevent + * concurrent access to the undo log, except when segments need to be + * added or removed. + */ + LWLockAcquire(UndoLogLock, LW_SHARED); + + /* + * Rather than doing the file IO while we hold locks, we'll copy the + * meta-data into a palloc'd buffer. + */ + serialized_size = sizeof(UndoLogMetaData) * UndoLogNumSlots(); + serialized = (UndoLogMetaData *) palloc0(serialized_size); + + /* Scan through all slots looking for non-empty ones. */ + num_logs = 0; + for (i = 0; i < UndoLogNumSlots(); ++i) + { + UndoLogSlot *slot = &UndoLogShared->slots[i]; + + /* Skip empty slots. */ + if (slot->logno == InvalidUndoLogNumber) + continue; + + /* Capture snapshot while holding each mutex. */ + LWLockAcquire(&slot->mutex, LW_EXCLUSIVE); + serialized[num_logs++] = slot->meta; + LWLockRelease(&slot->mutex); + } + + LWLockRelease(UndoLogLock); + + /* Dump into a file under pg_undo. */ + snprintf(path, MAXPGPATH, "pg_undo/%016" INT64_MODIFIER "X", + checkPointRedo); + pgstat_report_wait_start(WAIT_EVENT_UNDO_CHECKPOINT_WRITE); + fd = OpenTransientFile(path, O_RDWR | O_CREAT | PG_BINARY); + if (fd < 0) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not create file \"%s\": %m", path))); + + /* Compute header checksum. */ + INIT_CRC32C(crc); + COMP_CRC32C(crc, &UndoLogShared->low_logno, sizeof(UndoLogShared->low_logno)); + COMP_CRC32C(crc, &UndoLogShared->next_logno, sizeof(UndoLogShared->next_logno)); + COMP_CRC32C(crc, &num_logs, sizeof(num_logs)); + FIN_CRC32C(crc); + + /* Write out the number of active logs + crc. */ + if ((write(fd, &UndoLogShared->low_logno, sizeof(UndoLogShared->low_logno)) != sizeof(UndoLogShared->low_logno)) || + (write(fd, &UndoLogShared->next_logno, sizeof(UndoLogShared->next_logno)) != sizeof(UndoLogShared->next_logno)) || + (write(fd, &num_logs, sizeof(num_logs)) != sizeof(num_logs)) || + (write(fd, &crc, sizeof(crc)) != sizeof(crc))) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not write to file \"%s\": %m", path))); + + /* Write out the meta data for all active undo logs. */ + data = (char *) serialized; + INIT_CRC32C(crc); + serialized_size = num_logs * sizeof(UndoLogMetaData); + while (serialized_size > 0) + { + ssize_t written; + + written = write(fd, data, serialized_size); + if (written < 0) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not write to file \"%s\": %m", path))); + COMP_CRC32C(crc, data, written); + serialized_size -= written; + data += written; + } + FIN_CRC32C(crc); + + if (write(fd, &crc, sizeof(crc)) != sizeof(crc)) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not write to file \"%s\": %m", path))); + + + /* Flush file and directory entry. */ + pgstat_report_wait_start(WAIT_EVENT_UNDO_CHECKPOINT_SYNC); + pg_fsync(fd); + if (CloseTransientFile(fd) < 0) + ereport(data_sync_elevel(ERROR), + (errcode_for_file_access(), + errmsg("could not close file \"%s\": %m", path))); + fsync_fname("pg_undo", true); + pgstat_report_wait_end(); + + if (serialized) + pfree(serialized); + + CleanUpUndoCheckPointFiles(priorCheckPointRedo); +} + +void +StartupUndoLogs(XLogRecPtr checkPointRedo) +{ + char path[MAXPGPATH]; + int i; + int fd; + int nlogs; + pg_crc32c crc; + pg_crc32c new_crc; + + /* If initdb is calling, there is no file to read yet. */ + if (IsBootstrapProcessingMode()) + return; + + /* Open the pg_undo file corresponding to the given checkpoint. */ + snprintf(path, MAXPGPATH, "pg_undo/%016" INT64_MODIFIER "X", + checkPointRedo); + pgstat_report_wait_start(WAIT_EVENT_UNDO_CHECKPOINT_READ); + fd = OpenTransientFile(path, O_RDONLY | PG_BINARY); + if (fd < 0) + elog(ERROR, "cannot open undo checkpoint snapshot \"%s\": %m", path); + + /* Read the active log number range. */ + if ((read(fd, &UndoLogShared->low_logno, sizeof(UndoLogShared->low_logno)) + != sizeof(UndoLogShared->low_logno)) || + (read(fd, &UndoLogShared->next_logno, sizeof(UndoLogShared->next_logno)) + != sizeof(UndoLogShared->next_logno)) || + (read(fd, &nlogs, sizeof(nlogs)) != sizeof(nlogs)) || + (read(fd, &crc, sizeof(crc)) != sizeof(crc))) + elog(ERROR, "pg_undo file \"%s\" is corrupted", path); + + /* Verify the header checksum. */ + INIT_CRC32C(new_crc); + COMP_CRC32C(new_crc, &UndoLogShared->low_logno, sizeof(UndoLogShared->low_logno)); + COMP_CRC32C(new_crc, &UndoLogShared->next_logno, sizeof(UndoLogShared->next_logno)); + COMP_CRC32C(new_crc, &nlogs, sizeof(UndoLogShared->next_logno)); + FIN_CRC32C(new_crc); + + if (crc != new_crc) + elog(ERROR, + "pg_undo file \"%s\" has incorrect checksum", path); + + /* + * We'll acquire UndoLogLock just because allocate_undo_log() asserts we + * hold it (we don't actually expect concurrent access yet). + */ + LWLockAcquire(UndoLogLock, LW_EXCLUSIVE); + + /* Initialize all the logs and set up the freelist. */ + INIT_CRC32C(new_crc); + for (i = 0; i < nlogs; ++i) + { + ssize_t size; + UndoLogSlot *slot; + + /* + * Get a new UndoLogSlot. If this checkpoint was created on a system + * with a higher max_connections setting, it's theoretically possible + * that we don't have enough space and cannot start up. + */ + slot = allocate_undo_log_slot(); + if (!slot) + ereport(ERROR, + (errmsg("not enough undo log slots to recover from checkpoint: need at least %d, have %zu", + nlogs, UndoLogNumSlots()), + errhint("Consider increasing max_connections"))); + + /* Read in the meta data for this undo log. */ + if ((size = read(fd, &slot->meta, sizeof(slot->meta))) != sizeof(slot->meta)) + elog(ERROR, "short read of pg_undo meta data in file \"%s\": %m (got %zu, wanted %zu)", + path, size, sizeof(slot->meta)); + COMP_CRC32C(new_crc, &slot->meta, sizeof(slot->meta)); + + /* + * At normal start-up, or during recovery, all active undo logs start + * out on the appropriate free list. + */ + slot->logno = slot->meta.logno; + slot->pid = InvalidPid; + slot->oldest_data = MakeUndoRecPtr(slot->logno, slot->meta.discard); + if (slot->meta.status == UNDO_LOG_STATUS_ACTIVE) + { + slot->next_free = UndoLogShared->free_lists[slot->meta.category]; + UndoLogShared->free_lists[slot->meta.category] = slot->logno; + } + } + FIN_CRC32C(new_crc); + + LWLockRelease(UndoLogLock); + + /* Verify body checksum. */ + if (read(fd, &crc, sizeof(crc)) != sizeof(crc)) + elog(ERROR, "pg_undo file \"%s\" is corrupted", path); + if (crc != new_crc) + elog(ERROR, + "pg_undo file \"%s\" has incorrect checksum", path); + + CloseTransientFile(fd); + pgstat_report_wait_end(); +} + +/* + * Allocate a new UndoLogSlot object. + */ +static UndoLogSlot * +allocate_undo_log_slot(void) +{ + UndoLogSlot *slot; + UndoLogNumber i; + + Assert(LWLockHeldByMeInMode(UndoLogLock, LW_EXCLUSIVE)); + + for (i = 0; i < UndoLogNumSlots(); ++i) + { + slot = &UndoLogShared->slots[i]; + if (slot->logno == InvalidUndoLogNumber) + { + memset(&slot->meta, 0, sizeof(slot->meta)); + slot->pid = 0; + slot->wait_fxmin = InvalidFullTransactionId; + slot->oldest_data =0; + slot->next_free = -1; + slot->logno = -1; + return slot; + } + } + + return NULL; +} + +/* + * Free an UndoLogSlot object in shared memory, so that it can be reused. + * This is a rare event, and has complications for all code paths that access + * slots. Unless the current session is attached to the slot, it must be + * prepared for it to be freed and then potentially recycled for use by + * another log. See UndoLogGetSlot(). + */ +static void +free_undo_log_slot(UndoLogSlot *slot) +{ + /* + * When removing an undo log from a slot in shared memory, we acquire + * UndoLogLock, log->mutex and log->discard_lock, so that other code can + * hold any one of those locks to prevent the slot from being recycled. + */ + LWLockAcquire(UndoLogLock, LW_EXCLUSIVE); + LWLockAcquire(&slot->mutex, LW_EXCLUSIVE); + Assert(slot->logno != InvalidUndoLogNumber); + slot->logno = InvalidUndoLogNumber; + memset(&slot->meta, 0, sizeof(slot->meta)); + LWLockRelease(&slot->mutex); + LWLockRelease(UndoLogLock); +} + +/* + * Find the UndoLogSlot object for a given log number. + * + * The caller may or may not already hold UndoLogLock, and should indicate + * this by passing 'locked'. We'll acquire it in the slow path if necessary. + * If it is not held by the caller, the caller must deal with the possibility + * that the returned UndoLogSlot no longer contains the requested logno by the + * time it is accessed. + * + * To do that, one of the following approaches must be taken by the calling + * code: + * + * 1. If the calling code knows that it is attached to this lock or is the + * recovery process, then there is no way for the slot to be recycled, so it's + * not necessary to check that the log number hasn't changed. The slot cannot + * be recycled while a backend is attached. It should probably assert that it + * is attached, however. + * + * 2. All other code should acquire log->mutex before accessing any members, + * and after doing so, check that the logno hasn't moved. If it is not, the + * entire undo log must be assumed to be discarded (as if this function + * returned NULL) and the caller must behave accordingly. + * + * Return NULL if the undo log has been entirely discarded. It is an error to + * ask for undo logs that have never been created. + */ +static UndoLogSlot * +find_undo_log_slot(UndoLogNumber logno, bool locked) +{ + UndoLogSlot *result = NULL; + UndoLogTableEntry *entry; + bool found; + + Assert(locked == LWLockHeldByMe(UndoLogLock)); + + /* First see if we already have it in our cache. */ + entry = undologtable_lookup(undologtable_cache, logno); + if (likely(entry)) + result = entry->slot; + else + { + UndoLogNumber i; + + /* Nope. Linear search for the slot in shared memory. */ + if (!locked) + LWLockAcquire(UndoLogLock, LW_SHARED); + for (i = 0; i < UndoLogNumSlots(); ++i) + { + if (UndoLogShared->slots[i].logno == logno) + { + /* Found it. */ + + /* + * TODO: Should this function be usable in a critical section? + * Would it make sense to detect that we are in a critical + * section and just return the pointer to the log without + * updating the cache, to avoid any chance of allocating + * memory? + */ + + entry = undologtable_insert(undologtable_cache, logno, &found); + entry->number = logno; + entry->slot = &UndoLogShared->slots[i]; + entry->tablespace = entry->slot->meta.tablespace; + entry->category = entry->slot->meta.category; + entry->recent_discard = + MakeUndoRecPtr(logno, entry->slot->meta.discard); + result = entry->slot; + break; + } + } + + /* + * If we didn't find it, then it must already have been entirely + * discarded. We create a negative cache entry so that we can answer + * this question quickly next time. + * + * TODO: We could track the lowest known undo log number, to reduce + * the negative cache entry bloat. + */ + if (result == NULL) + { + /* + * Sanity check: the caller should not be asking about undo logs + * that have never existed. + */ + if (logno >= UndoLogShared->next_logno) + elog(ERROR, "undo log %u hasn't been created yet", logno); + entry = undologtable_insert(undologtable_cache, logno, &found); + entry->number = logno; + entry->slot = NULL; + entry->tablespace = 0; + } + if (!locked) + LWLockRelease(UndoLogLock); + } + + return result; +} + +/* + * Get a pointer to an UndoLogSlot object corresponding to a given logno. + * + * In general, the caller must acquire the UndoLogSlot's mutex to access + * the contents, and at that time must consider that the logno might have + * changed because the undo log it contained has been entirely discarded. + * + * If the calling backend is currently attached to the undo log, that is not + * possible, because logs can only reach UNDO_LOG_STATUS_DISCARDED after first + * reaching UNDO_LOG_STATUS_FULL, and that only happens while detaching. + */ +UndoLogSlot * +UndoLogGetSlot(UndoLogNumber logno, bool missing_ok) +{ + UndoLogSlot *slot = find_undo_log_slot(logno, false); + + if (slot == NULL && !missing_ok) + elog(ERROR, "unknown undo log number %d", logno); + + return slot; +} + +/* + * Attach to a free undo log, creating a new one if required. + */ +static void +attach_undo_log(UndoLogCategory category, Oid tablespace) +{ + UndoLogSlot *slot = NULL; + UndoLogNumber logno; + UndoLogNumber *place; + + Assert(!InRecovery); + Assert(CurrentSession->attached_undo_slots[category] == NULL); + + LWLockAcquire(UndoLogLock, LW_EXCLUSIVE); + + /* + * For now we have a simple linked list of unattached undo logs for each + * persistence level. We'll grovel though it to find something for the + * tablespace you asked for. If you're not using multiple tablespaces + * it'll be able to pop one off the front. We might need a hash table + * keyed by tablespace if this simple scheme turns out to be too slow when + * using many tablespaces and many undo logs, but that seems like an + * unusual use case not worth optimizing for. + */ + place = &UndoLogShared->free_lists[category]; + while (*place != InvalidUndoLogNumber) + { + UndoLogSlot *candidate = find_undo_log_slot(*place, true); + + /* + * There should never be an undo log on the freelist that has been + * entirely discarded, or hasn't been created yet. The persistence + * level should match the freelist. + */ + if (unlikely(candidate == NULL)) + elog(ERROR, + "corrupted undo log freelist, no such undo log %u", *place); + if (unlikely(candidate->meta.category != category)) + elog(ERROR, + "corrupted undo log freelist, undo log %u with persistence %d found on freelist %d", + *place, candidate->meta.category, category); + + if (candidate->meta.tablespace == tablespace) + { + logno = *place; + slot = candidate; + *place = candidate->next_free; + break; + } + place = &candidate->next_free; + } + + /* + * If all existing undo logs for this tablespace and persistence level are + * busy, we'll have to create a new one. + */ + if (slot == NULL) + { + if (UndoLogShared->next_logno > MaxUndoLogNumber) + { + /* + * You've used up all 16 exabytes of undo log addressing space. + * This is a difficult state to reach using only 16 exabytes of + * WAL. + */ + elog(ERROR, "undo log address space exhausted"); + } + + /* Allocate a slot from the UndoLogSlot pool. */ + slot = allocate_undo_log_slot(); + if (unlikely(!slot)) + ereport(ERROR, + (errmsg("could not create new undo log"), + errdetail("The maximum number of active undo logs is %zu.", + UndoLogNumSlots()), + errhint("Consider increasing max_connections."))); + slot->logno = logno = UndoLogShared->next_logno; + + /* + * The insert and discard pointers start after the first block's + * header. XXX That means that insert is > end for a short time in a + * newly created undo log. Is there any problem with that? + */ + slot->meta.unlogged.insert = UndoLogBlockHeaderSize; + slot->meta.discard = UndoLogBlockHeaderSize; + + slot->meta.logno = logno; + slot->meta.tablespace = tablespace; + slot->meta.category = category; + slot->meta.status = UNDO_LOG_STATUS_ACTIVE; + + /* Move the high log number pointer past this one. */ + ++UndoLogShared->next_logno; + + /* WAL-log the creation of this new undo log. */ + { + xl_undolog_create xlrec; + + xlrec.logno = logno; + xlrec.tablespace = slot->meta.tablespace; + xlrec.category = slot->meta.category; + + XLogBeginInsert(); + XLogRegisterData((char *) &xlrec, sizeof(xlrec)); + XLogInsert(RM_UNDOLOG_ID, XLOG_UNDOLOG_CREATE); + } + + /* + * This undo log has no segments. UndoLogAllocate will create the + * first one on demand. + */ + } + LWLockRelease(UndoLogLock); + + LWLockAcquire(&slot->mutex, LW_EXCLUSIVE); + slot->pid = MyProcPid; + LWLockRelease(&slot->mutex); + + CurrentSession->attached_undo_slots[category] = slot; +} + +/* check_hook: validate new undo_tablespaces */ +bool +check_undo_tablespaces(char **newval, void **extra, GucSource source) +{ + char *rawname; + List *namelist; + + /* Need a modifiable copy of string */ + rawname = pstrdup(*newval); + + /* + * Parse string into list of identifiers, just to check for + * well-formedness (unfortunateley we can't validate the names in the + * catalog yet). + */ + if (!SplitIdentifierString(rawname, ',', &namelist)) + { + /* syntax error in name list */ + GUC_check_errdetail("List syntax is invalid."); + pfree(rawname); + list_free(namelist); + return false; + } + + /* + * Make sure we aren't already in a transaction that has been assigned an + * XID. This ensures we don't detach from an undo log that we might have + * started writing undo data into for this transaction. + */ + if (GetTopTransactionIdIfAny() != InvalidTransactionId) + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + (errmsg("undo_tablespaces cannot be changed while a transaction is in progress")))); + list_free(namelist); + + return true; +} + +/* assign_hook: do extra actions as needed */ +void +assign_undo_tablespaces(const char *newval, void *extra) +{ + /* + * This is normally called only when GetTopTransactionIdIfAny() == + * InvalidTransactionId (because you can't change undo_tablespaces in the + * middle of a transaction that's been asigned an xid), but we can't + * assert that because it's also called at the end of a transaction that's + * rolling back, to reset the GUC if it was set inside the transaction. + */ + + /* Tell UndoLogAllocate() to reexamine undo_tablespaces. */ + if (CurrentSession) + CurrentSession->need_to_choose_undo_tablespace = true; +} + +static bool +choose_undo_tablespace(bool force_detach, Oid *tablespace) +{ + char *rawname; + List *namelist; + bool need_to_unlock; + int length; + int i; + + /* We need a modifiable copy of string. */ + rawname = pstrdup(undo_tablespaces); + + /* Break string into list of identifiers. */ + if (!SplitIdentifierString(rawname, ',', &namelist)) + elog(ERROR, "undo_tablespaces is unexpectedly malformed"); + + length = list_length(namelist); + if (length == 0 || + (length == 1 && ((char *) linitial(namelist))[0] == '\0')) + { + /* + * If it's an empty string, then we'll use the default tablespace. No + * locking is required because it can't be dropped. + */ + *tablespace = DEFAULTTABLESPACE_OID; + need_to_unlock = false; + } + else + { + /* + * Choose an OID using our pid, so that if several backends have the + * same multi-tablespace setting they'll spread out. We could easily + * do better than this if more serious load balancing is judged + * useful. + */ + int index = MyProcPid % length; + int first_index = index; + Oid oid = InvalidOid; + + /* + * Take the tablespace create/drop lock while we look the name up. + * This prevents the tablespace from being dropped while we're trying + * to resolve the name, or while the called is trying to create an + * undo log in it. The caller will have to release this lock. + */ + LWLockAcquire(TablespaceCreateLock, LW_EXCLUSIVE); + for (;;) + { + const char *name = list_nth(namelist, index); + + oid = get_tablespace_oid(name, true); + if (oid == InvalidOid) + { + /* Unknown tablespace, try the next one. */ + index = (index + 1) % length; + /* + * But if we've tried them all, it's time to complain. We'll + * arbitrarily complain about the last one we tried in the + * error message. + */ + if (index == first_index) + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_OBJECT), + errmsg("tablespace \"%s\" does not exist", name), + errhint("Create the tablespace or set undo_tablespaces to a valid or empty list."))); + continue; + } + if (oid == GLOBALTABLESPACE_OID) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("undo logs cannot be placed in pg_global tablespace"))); + /* If we got here we succeeded in finding one. */ + break; + } + + Assert(oid != InvalidOid); + *tablespace = oid; + need_to_unlock = true; + } + + /* + * If we came here because the user changed undo_tablesaces, then detach + * from any undo logs we happen to be attached to. + */ + if (force_detach) + { + for (i = 0; i < UndoLogCategories; ++i) + { + UndoLogSlot *slot = CurrentSession->attached_undo_slots[i]; + + if (slot != NULL) + { + LWLockAcquire(&slot->mutex, LW_EXCLUSIVE); + slot->pid = InvalidPid; + slot->meta.unlogged.xid = InvalidTransactionId; + LWLockRelease(&slot->mutex); + + LWLockAcquire(UndoLogLock, LW_EXCLUSIVE); + slot->next_free = UndoLogShared->free_lists[i]; + UndoLogShared->free_lists[i] = slot->logno; + LWLockRelease(UndoLogLock); + + CurrentSession->attached_undo_slots[i] = NULL; + } + } + } + + return need_to_unlock; +} + +bool +DropUndoLogsInTablespace(Oid tablespace) +{ + DIR *dir; + char undo_path[MAXPGPATH]; + UndoLogSlot *slot = NULL; + int i; + + Assert(LWLockHeldByMe(TablespaceCreateLock)); + Assert(tablespace != DEFAULTTABLESPACE_OID); + + /* First, try to kick everyone off any undo logs in this tablespace. */ + while ((slot = UndoLogNextSlot(slot))) + { + bool ok; + bool return_to_freelist = false; + + /* Skip undo logs in other tablespaces. */ + if (slot->meta.tablespace != tablespace) + continue; + + /* Check if this undo log can be forcibly detached. */ + LWLockAcquire(&slot->mutex, LW_EXCLUSIVE); + if (slot->meta.discard == slot->meta.unlogged.insert && + (slot->meta.unlogged.xid == InvalidTransactionId || + !TransactionIdIsInProgress(slot->meta.unlogged.xid))) + { + slot->meta.unlogged.xid = InvalidTransactionId; + if (slot->pid != InvalidPid) + { + slot->pid = InvalidPid; + return_to_freelist = true; + } + ok = true; + } + else + { + /* + * There is data we need in this undo log. We can't force it to + * be detached. + */ + ok = false; + } + LWLockRelease(&slot->mutex); + + /* If we failed, then give up now and report failure. */ + if (!ok) + return false; + + /* + * Put this undo log back on the appropriate free-list. No one can + * attach to it while we hold TablespaceCreateLock, but if we return + * earlier in a future go around this loop, we need the undo log to + * remain usable. We'll remove all appropriate logs from the + * free-lists in a separate step below. + */ + if (return_to_freelist) + { + LWLockAcquire(UndoLogLock, LW_EXCLUSIVE); + slot->next_free = UndoLogShared->free_lists[slot->meta.category]; + UndoLogShared->free_lists[slot->meta.category] = slot->logno; + LWLockRelease(UndoLogLock); + } + } + + /* + * We detached all backends from undo logs in this tablespace, and no one + * can attach to any non-default-tablespace undo logs while we hold + * TablespaceCreateLock. We can now drop the undo logs. + */ + slot = NULL; + while ((slot = UndoLogNextSlot(slot))) + { + /* Skip undo logs in other tablespaces. */ + if (slot->meta.tablespace != tablespace) + continue; + + /* + * Make sure no buffers remain. When that is done by + * UndoLogDiscard(), the final page is left in shared_buffers because + * it may contain data, or at least be needed again very soon. Here + * we need to drop even that page from the buffer pool. + */ + forget_undo_buffers(slot->logno, slot->meta.discard, slot->meta.discard, true); + + /* + * TODO: For now we drop the undo log, meaning that it will never be + * used again. That wastes the rest of its address space. Instead, + * we should put it onto a special list of 'offline' undo logs, ready + * to be reactivated in some other tablespace. Then we can keep the + * unused portion of its address space. + */ + LWLockAcquire(&slot->mutex, LW_EXCLUSIVE); + slot->meta.status = UNDO_LOG_STATUS_DISCARDED; + LWLockRelease(&slot->mutex); + } + + /* Forget about all sync requests relating to this tablespace. */ + undofile_forget_sync_tablespace(tablespace); + + /* Unlink all undo segment files in this tablespace. */ + UndoLogDirectory(tablespace, undo_path); + + dir = AllocateDir(undo_path); + if (dir != NULL) + { + struct dirent *de; + + while ((de = ReadDirExtended(dir, undo_path, LOG)) != NULL) + { + char segment_path[MAXPGPATH]; + + if (strcmp(de->d_name, ".") == 0 || + strcmp(de->d_name, "..") == 0) + continue; + snprintf(segment_path, sizeof(segment_path), "%s/%s", + undo_path, de->d_name); + if (unlink(segment_path) < 0) + elog(LOG, "couldn't unlink file \"%s\": %m", segment_path); + } + FreeDir(dir); + } + + /* Remove all dropped undo logs from the free-lists. */ + LWLockAcquire(UndoLogLock, LW_EXCLUSIVE); + for (i = 0; i < UndoLogCategories; ++i) + { + UndoLogSlot *slot; + UndoLogNumber *place; + + place = &UndoLogShared->free_lists[i]; + while (*place != InvalidUndoLogNumber) + { + slot = find_undo_log_slot(*place, true); + if (!slot) + elog(ERROR, + "corrupted undo log freelist, unknown log %u", *place); + if (slot->meta.status == UNDO_LOG_STATUS_DISCARDED) + *place = slot->next_free; + else + place = &slot->next_free; + } + } + LWLockRelease(UndoLogLock); + + return true; +} + +void +ResetUndoLogs(UndoLogCategory category) +{ + UndoLogSlot *slot = NULL; + + while ((slot = UndoLogNextSlot(slot))) + { + DIR *dir; + struct dirent *de; + char undo_path[MAXPGPATH]; + char segment_prefix[MAXPGPATH]; + size_t segment_prefix_size; + + if (slot->meta.category != category) + continue; + + /* Scan the directory for files belonging to this undo log. */ + snprintf(segment_prefix, sizeof(segment_prefix), "%06X.", slot->logno); + segment_prefix_size = strlen(segment_prefix); + UndoLogDirectory(slot->meta.tablespace, undo_path); + dir = AllocateDir(undo_path); + if (dir == NULL) + continue; + while ((de = ReadDirExtended(dir, undo_path, LOG)) != NULL) + { + char segment_path[MAXPGPATH]; + + if (strncmp(de->d_name, segment_prefix, segment_prefix_size) != 0) + continue; + snprintf(segment_path, sizeof(segment_path), "%s/%s", + undo_path, de->d_name); + elog(DEBUG1, "unlinked undo segment \"%s\"", segment_path); + if (unlink(segment_path) < 0) + elog(LOG, "couldn't unlink file \"%s\": %m", segment_path); + } + FreeDir(dir); + + /* + * We have no segment files. Set the pointers to indicate that there + * is no data. The discard and insert pointers point to the first + * usable byte in the segment we will create when we next try to + * allocate. This is a bit strange, because it means that they are + * past the end pointer. That's the same as when new undo logs are + * created. + * + * TODO: Should we rewind to zero instead, so we can reuse that (now) + * unreferenced address space? + */ + slot->meta.unlogged.insert = slot->meta.discard = slot->meta.end + + UndoLogBlockHeaderSize; + } +} + +Datum +pg_stat_get_undo_logs(PG_FUNCTION_ARGS) +{ +#define PG_STAT_GET_UNDO_LOGS_COLS 9 + ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; + TupleDesc tupdesc; + Tuplestorestate *tupstore; + MemoryContext per_query_ctx; + MemoryContext oldcontext; + char *tablespace_name = NULL; + Oid last_tablespace = InvalidOid; + int i; + + /* check to see if caller supports us returning a tuplestore */ + if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo)) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("set-valued function called in context that cannot accept a set"))); + if (!(rsinfo->allowedModes & SFRM_Materialize)) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("materialize mode required, but it is not " \ + "allowed in this context"))); + + /* Build a tuple descriptor for our result type */ + if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) + elog(ERROR, "return type must be a row type"); + + per_query_ctx = rsinfo->econtext->ecxt_per_query_memory; + oldcontext = MemoryContextSwitchTo(per_query_ctx); + + tupstore = tuplestore_begin_heap(true, false, work_mem); + rsinfo->returnMode = SFRM_Materialize; + rsinfo->setResult = tupstore; + rsinfo->setDesc = tupdesc; + + MemoryContextSwitchTo(oldcontext); + + /* Scan all undo logs to build the results. */ + for (i = 0; i < UndoLogShared->nslots; ++i) + { + UndoLogSlot *slot = &UndoLogShared->slots[i]; + char buffer[17]; + Datum values[PG_STAT_GET_UNDO_LOGS_COLS]; + bool nulls[PG_STAT_GET_UNDO_LOGS_COLS] = { false }; + Oid tablespace; + + /* + * This won't be a consistent result overall, but the values for each + * log will be consistent because we'll take the per-log lock while + * copying them. + */ + LWLockAcquire(&slot->mutex, LW_SHARED); + + /* Skip unused slots and entirely discarded undo logs. */ + if (slot->logno == InvalidUndoLogNumber || + slot->meta.status == UNDO_LOG_STATUS_DISCARDED) + { + LWLockRelease(&slot->mutex); + continue; + } + + values[0] = ObjectIdGetDatum((Oid) slot->logno); + values[1] = CStringGetTextDatum( + slot->meta.category == UNDO_PERMANENT ? "permanent" : + slot->meta.category == UNDO_UNLOGGED ? "unlogged" : + slot->meta.category == UNDO_TEMP ? "temporary" : + slot->meta.category == UNDO_SHARED ? "shared" : "<unknown>"); + tablespace = slot->meta.tablespace; + + snprintf(buffer, sizeof(buffer), UndoRecPtrFormat, + MakeUndoRecPtr(slot->logno, slot->meta.discard)); + values[3] = CStringGetTextDatum(buffer); + snprintf(buffer, sizeof(buffer), UndoRecPtrFormat, + MakeUndoRecPtr(slot->logno, slot->meta.unlogged.insert)); + values[4] = CStringGetTextDatum(buffer); + snprintf(buffer, sizeof(buffer), UndoRecPtrFormat, + MakeUndoRecPtr(slot->logno, slot->meta.end)); + values[5] = CStringGetTextDatum(buffer); + if (slot->meta.unlogged.xid == InvalidTransactionId) + nulls[6] = true; + else + values[6] = TransactionIdGetDatum(slot->meta.unlogged.xid); + if (slot->pid == InvalidPid) + nulls[7] = true; + else + values[7] = Int32GetDatum((int32) slot->pid); + switch (slot->meta.status) + { + case UNDO_LOG_STATUS_ACTIVE: + values[8] = CStringGetTextDatum("ACTIVE"); break; + case UNDO_LOG_STATUS_FULL: + values[8] = CStringGetTextDatum("FULL"); break; + default: + nulls[8] = true; + } + LWLockRelease(&slot->mutex); + + /* + * Deal with potentially slow tablespace name lookup without the lock. + * Avoid making multiple calls to that expensive function for the + * common case of repeating tablespace. + */ + if (tablespace != last_tablespace) + { + if (tablespace_name) + pfree(tablespace_name); + tablespace_name = get_tablespace_name(tablespace); + last_tablespace = tablespace; + } + if (tablespace_name) + { + values[2] = CStringGetTextDatum(tablespace_name); + nulls[2] = false; + } + else + nulls[2] = true; + + tuplestore_putvalues(tupstore, tupdesc, values, nulls); + } + + if (tablespace_name) + pfree(tablespace_name); + tuplestore_donestoring(tupstore); + + return (Datum) 0; +} + +/* + * replay the creation of a new undo log + */ +static void +undolog_xlog_create(XLogReaderState *record) +{ + xl_undolog_create *xlrec = (xl_undolog_create *) XLogRecGetData(record); + UndoLogSlot *slot; + + /* Create meta-data space in shared memory. */ + LWLockAcquire(UndoLogLock, LW_EXCLUSIVE); + + /* TODO: assert that it doesn't exist already? */ + + slot = allocate_undo_log_slot(); + LWLockAcquire(&slot->mutex, LW_EXCLUSIVE); + slot->logno = xlrec->logno; + slot->meta.logno = xlrec->logno; + slot->meta.status = UNDO_LOG_STATUS_ACTIVE; + slot->meta.category = xlrec->category; + slot->meta.tablespace = xlrec->tablespace; + slot->meta.unlogged.insert = UndoLogBlockHeaderSize; + slot->meta.discard = UndoLogBlockHeaderSize; + UndoLogShared->next_logno = Max(xlrec->logno + 1, UndoLogShared->next_logno); + LWLockRelease(&slot->mutex); + LWLockRelease(UndoLogLock); +} + +/* + * replay the addition of a new segment to an undo log + */ +static void +undolog_xlog_extend(XLogReaderState *record) +{ + xl_undolog_extend *xlrec = (xl_undolog_extend *) XLogRecGetData(record); + + /* Extend exactly as we would during DO phase. */ + extend_undo_log(xlrec->logno, xlrec->end); +} + +/* + * Drop all buffers for the given undo log, from the old_discard to up + * new_discard. If drop_tail is true, also drop the buffer that holds + * new_discard; this is used when discarding undo logs completely, for example + * via DROP TABLESPACE. If it is false, then the final buffer is not dropped + * because it may contain data. + * + */ +static void +forget_undo_buffers(int logno, UndoLogOffset old_discard, + UndoLogOffset new_discard, bool drop_tail) +{ + BlockNumber old_blockno; + BlockNumber new_blockno; + RelFileNode rnode; + + UndoRecPtrAssignRelFileNode(rnode, MakeUndoRecPtr(logno, old_discard)); + old_blockno = old_discard / BLCKSZ; + new_blockno = new_discard / BLCKSZ; + if (drop_tail) + ++new_blockno; + while (old_blockno < new_blockno) + { + ForgetBuffer(rnode, UndoLogForkNum, old_blockno); + ForgetLocalBuffer(rnode, UndoLogForkNum, old_blockno++); + } +} +/* + * replay an undo segment discard record + */ +static void +undolog_xlog_discard(XLogReaderState *record) +{ + xl_undolog_discard *xlrec = (xl_undolog_discard *) XLogRecGetData(record); + UndoLogSlot *slot; + UndoLogOffset discard; + UndoLogOffset end; + UndoLogOffset old_segment_begin; + UndoLogOffset new_segment_begin; + RelFileNode rnode = {0}; + + slot = find_undo_log_slot(xlrec->logno, false); + if (slot == NULL) + elog(ERROR, "unknown undo log %d", xlrec->logno); + + /* + * We're about to discard undologs. In Hot Standby mode, ensure that + * there's no queries running which need to get tuple from discarded undo. + * + * XXX we are passing empty rnode to the conflict function so that it can + * check conflict in all the backend regardless of which database the + * backend is connected. + */ + if (InHotStandby && TransactionIdIsValid(xlrec->latestxid)) + ResolveRecoveryConflictWithSnapshot(xlrec->latestxid, rnode); + + /* + * See if we need to unlink or rename any files, but don't consider it an + * error if we find that files are missing. Since UndoLogDiscard() + * performs filesystem operations before WAL logging or updating shmem + * which could be checkpointed, a crash could have left files already + * deleted, but we could replay WAL that expects the files to be there. + */ + + LWLockAcquire(&slot->mutex, LW_EXCLUSIVE); + Assert(slot->logno == xlrec->logno); + discard = slot->meta.discard; + end = slot->meta.end; + LWLockRelease(&slot->mutex); + + /* Drop buffers before we remove/recycle any files. */ + forget_undo_buffers(xlrec->logno, discard, xlrec->discard, + xlrec->entirely_discarded); + + /* Rewind to the start of the segment. */ + old_segment_begin = discard - discard % UndoLogSegmentSize; + new_segment_begin = xlrec->discard - xlrec->discard % UndoLogSegmentSize; + + /* Unlink or rename segments that are no longer in range. */ + while (old_segment_begin < new_segment_begin) + { + char discard_path[MAXPGPATH]; + + /* Tell the checkpointer that the file is going away. */ + undofile_forget_sync(slot->logno, + old_segment_begin / UndoLogSegmentSize, + slot->meta.tablespace); + + UndoLogSegmentPath(xlrec->logno, old_segment_begin / UndoLogSegmentSize, + slot->meta.tablespace, discard_path); + + /* Can we recycle the oldest segment? */ + if (end < xlrec->end) + { + char recycle_path[MAXPGPATH]; + + UndoLogSegmentPath(xlrec->logno, end / UndoLogSegmentSize, + slot->meta.tablespace, recycle_path); + if (rename(discard_path, recycle_path) == 0) + { + elog(DEBUG1, "recycled undo segment \"%s\" -> \"%s\"", + discard_path, recycle_path); + end += UndoLogSegmentSize; + } + else + { + elog(LOG, "could not rename \"%s\" to \"%s\": %m", + discard_path, recycle_path); + } + } + else + { + if (unlink(discard_path) == 0) + elog(DEBUG1, "unlinked undo segment \"%s\"", discard_path); + else + elog(LOG, "could not unlink \"%s\": %m", discard_path); + } + old_segment_begin += UndoLogSegmentSize; + } + + /* Create any further new segments that are needed the slow way. */ + while (end < xlrec->end) + { + allocate_empty_undo_segment(xlrec->logno, slot->meta.tablespace, end); + end += UndoLogSegmentSize; + } + + /* Flush the directory entries before next checkpoint. */ + undofile_request_sync_dir(slot->meta.tablespace); + + /* Update shmem. */ + LWLockAcquire(&slot->mutex, LW_EXCLUSIVE); + slot->meta.discard = xlrec->discard; + slot->meta.end = end; + LWLockRelease(&slot->mutex); + + /* If we discarded everything, the slot can be given up. */ + if (xlrec->entirely_discarded) + free_undo_log_slot(slot); +} + +/* + * replay the switch of a undo log + */ +static void +undolog_xlog_switch(XLogReaderState *record) +{ + xl_undolog_switch *xlrec = (xl_undolog_switch *) XLogRecGetData(record); + UndoLogSlot *slot; + + slot = find_undo_log_slot(xlrec->logno, false); + + /* + * Restore the log switch information in the MyUndoLogState this will be + * reset by following UndoLogAllocateDuringRecovery. + */ + slot->meta.unlogged.prevlog_xact_start = xlrec->prevlog_xact_start; + slot->meta.unlogged.prevlog_last_urp = xlrec->prevlog_last_urp; +} + +void +undolog_redo(XLogReaderState *record) +{ + uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK; + + switch (info) + { + case XLOG_UNDOLOG_CREATE: + undolog_xlog_create(record); + break; + case XLOG_UNDOLOG_EXTEND: + undolog_xlog_extend(record); + break; + case XLOG_UNDOLOG_DISCARD: + undolog_xlog_discard(record); + break; + case XLOG_UNDOLOG_SWITCH: + undolog_xlog_switch(record); + default: + elog(PANIC, "undo_redo: unknown op code %u", info); + } +} + +/* + * For assertions only. + */ +bool +AmAttachedToUndoLogSlot(UndoLogSlot *slot) +{ + /* + * In general, we can't access log's members without locking. But this + * function is intended only for asserting that you are attached, and + * while you're attached the slot can't be recycled, so don't bother + * locking. + */ + return CurrentSession->attached_undo_slots[slot->meta.category] == slot; +} + +/* + * For testing use only. This function is only used by the test_undo module. + */ +void +UndoLogDetachFull(void) +{ + int i; + + for (i = 0; i < UndoLogCategories; ++i) + if (CurrentSession->attached_undo_slots[i]) + detach_current_undo_log(i, true); +} diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c index 9238fbe..4671838 100644 --- a/src/backend/bootstrap/bootstrap.c +++ b/src/backend/bootstrap/bootstrap.c @@ -20,6 +20,7 @@ #include "access/genam.h" #include "access/heapam.h" #include "access/htup_details.h" +#include "access/session.h" #include "access/tableam.h" #include "access/xact.h" #include "access/xlog_internal.h" @@ -519,6 +520,8 @@ BootstrapModeMain(void) InitPostgres(NULL, InvalidOid, NULL, InvalidOid, NULL, false); + InitializeSession(); + /* Initialize stuff for bootstrap-file processing */ for (i = 0; i < MAXATTR; i++) { diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index ea4c85e..cbe04e4 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1062,6 +1062,10 @@ GRANT SELECT (subdbid, subname, subowner, subenabled, subslotname, subpublicatio ON pg_subscription TO public; +CREATE VIEW pg_stat_undo_logs AS + SELECT * + FROM pg_stat_get_undo_logs(); + -- -- We have a few function definitions in here, too. -- At some point there might be enough to justify breaking them out into diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c index 84efb41..17c28b2 100644 --- a/src/backend/commands/tablespace.c +++ b/src/backend/commands/tablespace.c @@ -55,6 +55,7 @@ #include "access/htup_details.h" #include "access/sysattr.h" #include "access/tableam.h" +#include "access/undolog.h" #include "access/xact.h" #include "access/xlog.h" #include "access/xloginsert.h" @@ -497,6 +498,20 @@ DropTableSpace(DropTableSpaceStmt *stmt) LWLockAcquire(TablespaceCreateLock, LW_EXCLUSIVE); /* + * Drop the undo logs in this tablespace. This will fail (without + * dropping anything) if there are undo logs that we can't afford to drop + * because they contain non-discarded data or a transaction is in + * progress. Since we hold TablespaceCreateLock, no other session will be + * able to attach to an undo log in this tablespace (or any tablespace + * except default) concurrently. + */ + if (!DropUndoLogsInTablespace(tablespaceoid)) + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("tablespace \"%s\" cannot be dropped because it contains non-empty undo logs", + tablespacename))); + + /* * Try to remove the physical infrastructure. */ if (!destroy_tablespace_directories(tablespaceoid, false)) @@ -1517,6 +1532,14 @@ tblspc_redo(XLogReaderState *record) { xl_tblspc_drop_rec *xlrec = (xl_tblspc_drop_rec *) XLogRecGetData(record); + /* This shouldn't be able to fail in recovery. */ + LWLockAcquire(TablespaceCreateLock, LW_EXCLUSIVE); + if (!DropUndoLogsInTablespace(xlrec->ts_id)) + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("tablespace cannot be dropped because it contains non-empty undo logs"))); + LWLockRelease(TablespaceCreateLock); + /* * If we issued a WAL record for a drop tablespace it implies that * there were no files in it at all when the DROP was done. That means diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index b4f2b28..c742861 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -4070,6 +4070,27 @@ pgstat_get_wait_io(WaitEventIO w) case WAIT_EVENT_TWOPHASE_FILE_WRITE: event_name = "TwophaseFileWrite"; break; + case WAIT_EVENT_UNDO_CHECKPOINT_READ: + event_name = "UndoCheckpointRead"; + break; + case WAIT_EVENT_UNDO_CHECKPOINT_WRITE: + event_name = "UndoCheckpointWrite"; + break; + case WAIT_EVENT_UNDO_CHECKPOINT_SYNC: + event_name = "UndoCheckpointSync"; + break; + case WAIT_EVENT_UNDO_FILE_READ: + event_name = "UndoFileRead"; + break; + case WAIT_EVENT_UNDO_FILE_WRITE: + event_name = "UndoFileWrite"; + break; + case WAIT_EVENT_UNDO_FILE_FLUSH: + event_name = "UndoFileFlush"; + break; + case WAIT_EVENT_UNDO_FILE_SYNC: + event_name = "UndoFileSync"; + break; case WAIT_EVENT_WALSENDER_TIMELINE_HISTORY_READ: event_name = "WALSenderTimelineHistoryRead"; break; diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c index d5f9b61..abcb5e5 100644 --- a/src/backend/replication/basebackup.c +++ b/src/backend/replication/basebackup.c @@ -1368,7 +1368,7 @@ sendFile(const char *readfilename, const char *tarfilename, struct stat *statbuf char *page; size_t pad; PageHeader phdr; - int segmentno = 0; + BlockNumber first_blkno = 0; char *segmentpath; bool verify_checksum = false; @@ -1406,12 +1406,18 @@ sendFile(const char *readfilename, const char *tarfilename, struct stat *statbuf segmentpath = strstr(filename, "."); if (segmentpath != NULL) { - segmentno = atoi(segmentpath + 1); - if (segmentno == 0) + char *end; + if (strstr(readfilename, "undo")) + first_blkno = strtol(segmentpath + 1, &end, 16) / BLCKSZ; + else + first_blkno = strtol(segmentpath + 1, &end, 10) * RELSEG_SIZE; + if (*end != '\0') ereport(ERROR, - (errmsg("invalid segment number %d in file \"%s\"", - segmentno, filename))); + (errmsg("invalid segment number in file \"%s\"", + filename))); } + else + first_blkno = 0; } } @@ -1451,7 +1457,7 @@ sendFile(const char *readfilename, const char *tarfilename, struct stat *statbuf */ if (!PageIsNew(page) && PageGetLSN(page) < startptr) { - checksum = pg_checksum_page((char *) page, blkno + segmentno * RELSEG_SIZE); + checksum = pg_checksum_page((char *) page, blkno + first_blkno); phdr = (PageHeader) page; if (phdr->pd_checksum != checksum) { diff --git a/src/backend/replication/logical/decode.c b/src/backend/replication/logical/decode.c index 151c3ef..d3a9c4d 100644 --- a/src/backend/replication/logical/decode.c +++ b/src/backend/replication/logical/decode.c @@ -154,6 +154,7 @@ LogicalDecodingProcessRecord(LogicalDecodingContext *ctx, XLogReaderState *recor case RM_COMMIT_TS_ID: case RM_REPLORIGIN_ID: case RM_GENERIC_ID: + case RM_UNDOLOG_ID: /* just deal with xid, and done */ ReorderBufferProcessXid(ctx->reorder, XLogRecGetXid(record), buf.origptr); diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 6f3a402..2b1d606 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -177,6 +177,7 @@ static PrivateRefCountEntry *NewPrivateRefCountEntry(Buffer buffer); static PrivateRefCountEntry *GetPrivateRefCountEntry(Buffer buffer, bool do_move); static inline int32 GetPrivateRefCount(Buffer buffer); static void ForgetPrivateRefCountEntry(PrivateRefCountEntry *ref); +static void InvalidateBuffer(BufferDesc *buf); /* * Ensure that the PrivateRefCountArray has sufficient space to store one more @@ -620,10 +621,12 @@ ReadBuffer(Relation reln, BlockNumber blockNum) * valid, the page is zeroed instead of throwing an error. This is intended * for non-critical data, where the caller is prepared to repair errors. * - * In RBM_ZERO_AND_LOCK mode, if the page isn't in buffer cache already, it's + * In RBM_ZERO mode, if the page isn't in buffer cache already, it's * filled with zeros instead of reading it from disk. Useful when the caller * is going to fill the page from scratch, since this saves I/O and avoids * unnecessary failure if the page-on-disk has corrupt page headers. + * + * In RBM_ZERO_AND_LOCK mode, the page is zeroed and also locked. * The page is returned locked to ensure that the caller has a chance to * initialize the page before it's made visible to others. * Caution: do not use this mode to read a page that is beyond the relation's @@ -674,24 +677,20 @@ ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, /* * ReadBufferWithoutRelcache -- like ReadBufferExtended, but doesn't require * a relcache entry for the relation. - * - * NB: At present, this function may only be used on permanent relations, which - * is OK, because we only use it during XLOG replay. If in the future we - * want to use it on temporary or unlogged relations, we could pass additional - * parameters. */ Buffer ReadBufferWithoutRelcache(RelFileNode rnode, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, - BufferAccessStrategy strategy) + BufferAccessStrategy strategy, + char relpersistence) { bool hit; - SMgrRelation smgr = smgropen(rnode, InvalidBackendId); - - Assert(InRecovery); + SMgrRelation smgr = smgropen(rnode, + relpersistence == RELPERSISTENCE_TEMP + ? MyBackendId : InvalidBackendId); - return ReadBuffer_common(smgr, RELPERSISTENCE_PERMANENT, forkNum, blockNum, + return ReadBuffer_common(smgr, relpersistence, forkNum, blockNum, mode, strategy, &hit); } @@ -885,7 +884,9 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum, * Read in the page, unless the caller intends to overwrite it and * just wants us to allocate a buffer. */ - if (mode == RBM_ZERO_AND_LOCK || mode == RBM_ZERO_AND_CLEANUP_LOCK) + if (mode == RBM_ZERO || + mode == RBM_ZERO_AND_LOCK || + mode == RBM_ZERO_AND_CLEANUP_LOCK) MemSet((char *) bufBlock, 0, BLCKSZ); else { @@ -1340,6 +1341,61 @@ BufferAlloc(SMgrRelation smgr, char relpersistence, ForkNumber forkNum, } /* + * ForgetBuffer -- drop a buffer from shared buffers + * + * If the buffer isn't present in shared buffers, nothing happens. If it is + * present, it is discarded without making any attempt to write it back out to + * the operating system. The caller must therefore somehow be sure that the + * data won't be needed for anything now or in the future. It assumes that + * there is no concurrent access to the block, except that it might be being + * concurrently written. + */ +void +ForgetBuffer(RelFileNode rnode, ForkNumber forkNum, BlockNumber blockNum) +{ + SMgrRelation smgr = smgropen(rnode, InvalidBackendId); + BufferTag tag; /* identity of target block */ + uint32 hash; /* hash value for tag */ + LWLock *partitionLock; /* buffer partition lock for it */ + int buf_id; + BufferDesc *bufHdr; + uint32 buf_state; + + /* create a tag so we can lookup the buffer */ + INIT_BUFFERTAG(tag, smgr->smgr_rnode.node, forkNum, blockNum); + + /* determine its hash code and partition lock ID */ + hash = BufTableHashCode(&tag); + partitionLock = BufMappingPartitionLock(hash); + + /* see if the block is in the buffer pool */ + LWLockAcquire(partitionLock, LW_SHARED); + buf_id = BufTableLookup(&tag, hash); + LWLockRelease(partitionLock); + + /* didn't find it, so nothing to do */ + if (buf_id < 0) + return; + + /* take the buffer header lock */ + bufHdr = GetBufferDescriptor(buf_id); + buf_state = LockBufHdr(bufHdr); + + /* + * The buffer might been evicted after we released the partition lock and + * before we acquired the buffer header lock. If so, the buffer we've + * locked might contain some other data which we shouldn't touch. If the + * buffer hasn't been recycled, we proceed to invalidate it. + */ + if (RelFileNodeEquals(bufHdr->tag.rnode, rnode) && + bufHdr->tag.blockNum == blockNum && + bufHdr->tag.forkNum == forkNum) + InvalidateBuffer(bufHdr); /* releases spinlock */ + else + UnlockBufHdr(bufHdr, buf_state); +} + +/* * InvalidateBuffer -- mark a shared buffer invalid and return it to the * freelist. * diff --git a/src/backend/storage/buffer/localbuf.c b/src/backend/storage/buffer/localbuf.c index f5f6a29..a6fe3db 100644 --- a/src/backend/storage/buffer/localbuf.c +++ b/src/backend/storage/buffer/localbuf.c @@ -273,6 +273,49 @@ LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum, } /* + * ForgetLocalBuffer - drop a buffer from local buffers + * + * This is similar to bufmgr.c's ForgetBuffer, except that we do not need + * to do any locking since this is all local. As with that function, this + * must be used very carefully, since we'll cheerfully throw away dirty + * buffers without any attempt to write them. + */ +void +ForgetLocalBuffer(RelFileNode rnode, ForkNumber forkNum, BlockNumber blockNum) +{ + SMgrRelation smgr = smgropen(rnode, BackendIdForTempRelations()); + BufferTag tag; /* identity of target block */ + LocalBufferLookupEnt *hresult; + BufferDesc *bufHdr; + uint32 buf_state; + + /* + * If somehow this is the first request in the session, there's nothing to + * do. (This probably shouldn't happen, though.) + */ + if (LocalBufHash == NULL) + return; + + /* create a tag so we can lookup the buffer */ + INIT_BUFFERTAG(tag, smgr->smgr_rnode.node, forkNum, blockNum); + + /* see if the block is in the local buffer pool */ + hresult = (LocalBufferLookupEnt *) + hash_search(LocalBufHash, (void *) &tag, HASH_REMOVE, NULL); + + /* didn't find it, so nothing to do */ + if (!hresult) + return; + + /* mark buffer invalid */ + bufHdr = GetLocalBufferDescriptor(hresult->id); + CLEAR_BUFFERTAG(bufHdr->tag); + buf_state = pg_atomic_read_u32(&bufHdr->state); + buf_state &= ~(BM_VALID | BM_TAG_VALID | BM_DIRTY); + pg_atomic_unlocked_write_u32(&bufHdr->state, buf_state); +} + +/* * MarkLocalBufferDirty - * mark a local buffer dirty */ diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 315c74c..3c4f053 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -322,7 +322,6 @@ static void pre_sync_fname(const char *fname, bool isdir, int elevel); static void datadir_fsync_fname(const char *fname, bool isdir, int elevel); static void unlink_if_exists_fname(const char *fname, bool isdir, int elevel); -static int fsync_fname_ext(const char *fname, bool isdir, bool ignore_perm, int elevel); static int fsync_parent_path(const char *fname, int elevel); @@ -3345,7 +3344,7 @@ unlink_if_exists_fname(const char *fname, bool isdir, int elevel) * * Returns 0 if the operation succeeded, -1 otherwise. */ -static int +int fsync_fname_ext(const char *fname, bool isdir, bool ignore_perm, int elevel) { int fd; diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c index d7d7335..12c3249 100644 --- a/src/backend/storage/ipc/ipci.c +++ b/src/backend/storage/ipc/ipci.c @@ -21,6 +21,7 @@ #include "access/nbtree.h" #include "access/subtrans.h" #include "access/twophase.h" +#include "access/undolog.h" #include "commands/async.h" #include "miscadmin.h" #include "pgstat.h" @@ -125,6 +126,7 @@ CreateSharedMemoryAndSemaphores(int port) size = add_size(size, ProcGlobalShmemSize()); size = add_size(size, XLOGShmemSize()); size = add_size(size, CLOGShmemSize()); + size = add_size(size, UndoLogShmemSize()); size = add_size(size, CommitTsShmemSize()); size = add_size(size, SUBTRANSShmemSize()); size = add_size(size, TwoPhaseShmemSize()); @@ -213,6 +215,7 @@ CreateSharedMemoryAndSemaphores(int port) */ XLOGShmemInit(); CLOGShmemInit(); + UndoLogShmemInit(); CommitTsShmemInit(); SUBTRANSShmemInit(); MultiXactShmemInit(); diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c index bc1aa88..5df658d 100644 --- a/src/backend/storage/lmgr/lwlock.c +++ b/src/backend/storage/lmgr/lwlock.c @@ -522,6 +522,8 @@ RegisterLWLockTranches(void) LWLockRegisterTranche(LWTRANCHE_PARALLEL_APPEND, "parallel_append"); LWLockRegisterTranche(LWTRANCHE_PARALLEL_HASH_JOIN, "parallel_hash_join"); LWLockRegisterTranche(LWTRANCHE_SXACT, "serializable_xact"); + LWLockRegisterTranche(LWTRANCHE_UNDOLOG, "undo_log"); + LWLockRegisterTranche(LWTRANCHE_UNDODISCARD, "undo_discard"); /* Register named tranches. */ for (i = 0; i < NamedLWLockTrancheRequests; i++) diff --git a/src/backend/storage/lmgr/lwlocknames.txt b/src/backend/storage/lmgr/lwlocknames.txt index db47843..4b42a1c 100644 --- a/src/backend/storage/lmgr/lwlocknames.txt +++ b/src/backend/storage/lmgr/lwlocknames.txt @@ -49,3 +49,4 @@ MultiXactTruncationLock 41 OldSnapshotTimeMapLock 42 LogicalRepWorkerLock 43 CLogTruncationLock 44 +UndoLogLock 45 diff --git a/src/backend/storage/smgr/Makefile b/src/backend/storage/smgr/Makefile index e486b7c..ff2e5e2 100644 --- a/src/backend/storage/smgr/Makefile +++ b/src/backend/storage/smgr/Makefile @@ -12,6 +12,6 @@ subdir = src/backend/storage/smgr top_builddir = ../../../.. include $(top_builddir)/src/Makefile.global -OBJS = md.o smgr.o +OBJS = md.o smgr.o undofile.o include $(top_srcdir)/src/backend/common.mk diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c index d00b275..93df85c 100644 --- a/src/backend/storage/smgr/smgr.c +++ b/src/backend/storage/smgr/smgr.c @@ -17,11 +17,13 @@ */ #include "postgres.h" +#include "catalog/database_internal.h" #include "lib/ilist.h" #include "storage/bufmgr.h" #include "storage/ipc.h" #include "storage/md.h" #include "storage/smgr.h" +#include "storage/undofile.h" #include "utils/hsearch.h" #include "utils/inval.h" @@ -81,6 +83,24 @@ static const f_smgr smgrsw[] = { .smgr_nblocks = mdnblocks, .smgr_truncate = mdtruncate, .smgr_immedsync = mdimmedsync, + }, + /* undo logs */ + { + .smgr_init = undofile_init, + .smgr_shutdown = undofile_shutdown, + .smgr_open = undofile_open, + .smgr_close = undofile_close, + .smgr_create = undofile_create, + .smgr_exists = undofile_exists, + .smgr_unlink = undofile_unlink, + .smgr_extend = undofile_extend, + .smgr_prefetch = undofile_prefetch, + .smgr_read = undofile_read, + .smgr_write = undofile_write, + .smgr_writeback = undofile_writeback, + .smgr_nblocks = undofile_nblocks, + .smgr_truncate = undofile_truncate, + .smgr_immedsync = undofile_immedsync, } }; @@ -105,6 +125,8 @@ smgrwhich(RelFileNode rnode) { switch (rnode.dbNode) { + case UndoDbOid: + return 1; /* undofile.c */ default: return 0; /* md.c */ } @@ -189,6 +211,7 @@ smgropen(RelFileNode rnode, BackendId backend) reln->smgr_fsm_nblocks = InvalidBlockNumber; reln->smgr_vm_nblocks = InvalidBlockNumber; reln->smgr_which = smgrwhich(rnode); + reln->private_data = NULL; /* implementation-specific initialization */ smgrsw[reln->smgr_which].smgr_open(reln); diff --git a/src/backend/storage/smgr/undofile.c b/src/backend/storage/smgr/undofile.c new file mode 100644 index 0000000..04d4514 --- /dev/null +++ b/src/backend/storage/smgr/undofile.c @@ -0,0 +1,422 @@ +/* + * undofile.h + * + * PostgreSQL undo file manager. This module provides SMGR-compatible + * interface to the files that back undo logs on the filesystem, so that undo + * log data can use the shared buffer pool. Other aspects of undo log + * management are provided by undolog.c, so the SMGR interfaces not directly + * concerned with reading, writing and flushing data are unimplemented. + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/storage/smgr/undofile.c + */ + +#include "postgres.h" + +#include "access/undolog.h" +#include "access/xlog.h" +#include "catalog/database_internal.h" +#include "miscadmin.h" +#include "pgstat.h" +#include "postmaster/bgwriter.h" +#include "storage/fd.h" +#include "storage/smgr.h" +#include "storage/undofile.h" +#include "utils/memutils.h" + +/* Populate a file tag describing an undo segment file. */ +#define INIT_UNDOFILETAG(a,xx_logno,xx_tbspc,xx_segno) \ +( \ + memset(&(a), 0, sizeof(FileTag)), \ + (a).handler = SYNC_HANDLER_UNDO, \ + (a).rnode.dbNode = UndoDbOid, \ + (a).rnode.spcNode = (xx_tbspc), \ + (a).rnode.relNode = (xx_logno), \ + (a).segno = (xx_segno) \ +) + +/* + * While md.c expects random access and has a small number of huge + * segments, undofile.c manages a potentially very large number of smaller + * segments and has a less random access pattern. Therefore, instead of + * keeping a potentially huge array of vfds we'll just keep the most + * recently accessed N. + * + * For now, N == 1, so we just need to hold onto one 'File' handle. + */ +typedef struct UndoFileState +{ + int mru_segno; + File mru_file; +} UndoFileState; + +static MemoryContext UndoFileCxt; + +static File undofile_open_segment_file(Oid relNode, Oid spcNode, + BlockNumber segno, bool missing_ok); +static File undofile_get_segment_file(SMgrRelation reln, BlockNumber segno); + +void +undofile_init(void) +{ + UndoFileCxt = AllocSetContextCreate(TopMemoryContext, + "UndoFileSmgr", + ALLOCSET_DEFAULT_SIZES); +} + +void +undofile_shutdown(void) +{ +} + +void +undofile_open(SMgrRelation reln) +{ + UndoFileState *state; + + state = MemoryContextAllocZero(UndoFileCxt, sizeof(UndoFileState)); + reln->private_data = state; +} + +void +undofile_close(SMgrRelation reln, ForkNumber forknum) +{ +} + +void +undofile_create(SMgrRelation reln, ForkNumber forknum, bool isRedo) +{ + /* + * File creation is managed by undolog.c, but xlogutils.c likes to call + * this just in case. Ignore. + */ +} + +bool +undofile_exists(SMgrRelation reln, ForkNumber forknum) +{ + elog(ERROR, "undofile_exists is not supported"); + + return false; /* not reached */ +} + +void +undofile_unlink(RelFileNodeBackend rnode, ForkNumber forknum, bool isRedo) +{ + elog(ERROR, "undofile_unlink is not supported"); +} + +void +undofile_extend(SMgrRelation reln, ForkNumber forknum, + BlockNumber blocknum, char *buffer, + bool skipFsync) +{ + elog(ERROR, "undofile_extend is not supported"); +} + +void +undofile_prefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum) +{ + elog(ERROR, "undofile_prefetch is not supported"); +} + +void +undofile_read(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, + char *buffer) +{ + File file; + off_t seekpos; + int nbytes; + + Assert(forknum == MAIN_FORKNUM); + file = undofile_get_segment_file(reln, blocknum / UNDOSEG_SIZE); + seekpos = (off_t) BLCKSZ * (blocknum % ((BlockNumber) UNDOSEG_SIZE)); + Assert(seekpos < (off_t) BLCKSZ * UNDOSEG_SIZE); + nbytes = FileRead(file, buffer, BLCKSZ, seekpos, WAIT_EVENT_UNDO_FILE_READ); + if (nbytes != BLCKSZ) + { + if (nbytes < 0) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not read block %u in file \"%s\": %m", + blocknum, FilePathName(file)))); + ereport(ERROR, + (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("could not read block %u in file \"%s\": read only %d of %d bytes", + blocknum, FilePathName(file), + nbytes, BLCKSZ))); + } +} + +void +undofile_write(SMgrRelation reln, ForkNumber forknum, + BlockNumber blocknum, char *buffer, + bool skipFsync) +{ + File file; + off_t seekpos; + int nbytes; + + Assert(forknum == MAIN_FORKNUM); + file = undofile_get_segment_file(reln, blocknum / UNDOSEG_SIZE); + seekpos = (off_t) BLCKSZ * (blocknum % ((BlockNumber) UNDOSEG_SIZE)); + Assert(seekpos < (off_t) BLCKSZ * UNDOSEG_SIZE); + nbytes = FileWrite(file, buffer, BLCKSZ, seekpos, WAIT_EVENT_UNDO_FILE_WRITE); + if (nbytes != BLCKSZ) + { + if (nbytes < 0) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not write block %u in file \"%s\": %m", + blocknum, FilePathName(file)))); + /* + * short write: unexpected, because this should be overwriting an + * entirely pre-allocated segment file + */ + ereport(ERROR, + (errcode(ERRCODE_DISK_FULL), + errmsg("could not write block %u in file \"%s\": wrote only %d of %d bytes", + blocknum, FilePathName(file), + nbytes, BLCKSZ))); + } + + /* Tell checkpointer this file is dirty. */ + if (!skipFsync && !SmgrIsTemp(reln)) + { + undofile_request_sync(reln->smgr_rnode.node.relNode, + blocknum / UNDOSEG_SIZE, + reln->smgr_rnode.node.spcNode); + } +} + +void +undofile_writeback(SMgrRelation reln, ForkNumber forknum, + BlockNumber blocknum, BlockNumber nblocks) +{ + while (nblocks > 0) + { + File file; + int nflush; + + file = undofile_get_segment_file(reln, blocknum / UNDOSEG_SIZE); + + /* compute number of desired writes within the current segment */ + nflush = Min(nblocks, + 1 + UNDOSEG_SIZE - (blocknum % UNDOSEG_SIZE)); + + FileWriteback(file, + (blocknum % UNDOSEG_SIZE) * BLCKSZ, + nflush * BLCKSZ, WAIT_EVENT_UNDO_FILE_FLUSH); + + nblocks -= nflush; + blocknum += nflush; + } +} + +BlockNumber +undofile_nblocks(SMgrRelation reln, ForkNumber forknum) +{ + /* + * xlogutils.c likes to call this to decide whether to read or extend; for + * now we lie and say the relation is big as possible. + */ + return UndoLogMaxSize / BLCKSZ; +} + +void +undofile_truncate(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks) +{ + elog(ERROR, "undofile_truncate is not supported"); +} + +void +undofile_immedsync(SMgrRelation reln, ForkNumber forknum) +{ + elog(ERROR, "undofile_immedsync is not supported"); +} + +static File undofile_open_segment_file(Oid relNode, Oid spcNode, + BlockNumber segno, bool missing_ok) +{ + File file; + char path[MAXPGPATH]; + + UndoLogSegmentPath(relNode, segno, spcNode, path); + file = PathNameOpenFile(path, O_RDWR | PG_BINARY); + + if (file <= 0 && (!missing_ok || errno != ENOENT)) + elog(ERROR, "cannot open undo segment file '%s': %m", path); + + return file; +} + +/* + * Get a File for a particular segment of a SMgrRelation representing an undo + * log. + */ +static File undofile_get_segment_file(SMgrRelation reln, BlockNumber segno) +{ + UndoFileState *state = (UndoFileState *) reln->private_data; + + /* If we have a file open already, check if we need to close it. */ + if (state->mru_file > 0 && state->mru_segno != segno) + { + /* These are not the blocks we're looking for. */ + FileClose(state->mru_file); + state->mru_file = 0; + } + + /* Check if we need to open a new file. */ + if (state->mru_file <= 0) + { + state->mru_file = + undofile_open_segment_file(reln->smgr_rnode.node.relNode, + reln->smgr_rnode.node.spcNode, + segno, InRecovery); + if (InRecovery && state->mru_file <= 0) + { + /* + * If in recovery, we may be trying to access a file that will + * later be unlinked. Tolerate missing files, creating a new + * zero-filled file as required. + */ + UndoLogNewSegment(reln->smgr_rnode.node.relNode, + reln->smgr_rnode.node.spcNode, + segno); + state->mru_file = + undofile_open_segment_file(reln->smgr_rnode.node.relNode, + reln->smgr_rnode.node.spcNode, + segno, false); + Assert(state->mru_file > 0); + } + state->mru_segno = segno; + } + + return state->mru_file; +} + +/* + * Callback to handle a queued sync request. + */ +int +undofile_syncfiletag(const FileTag *tag, char *path) +{ + SMgrRelation reln = smgropen(tag->rnode, InvalidBackendId); + File file; + + if (tag->rnode.relNode == (Oid) InvalidUndoLogNumber) + { + /* Sync parent directory for this tablespace. */ + UndoLogDirectory(tag->rnode.spcNode, path); + + /* The caller (sync.c) will do appropriate error reporting. */ + return fsync_fname_ext(path, true, false, WARNING); + } + else + { + /* Sync a segment file. */ + UndoLogSegmentPath(tag->rnode.relNode, tag->segno, tag->rnode.spcNode, + path); + + file = undofile_get_segment_file(reln, tag->segno); + if (file <= 0) + { + /* errno set by undofile_get_segment_file() */ + return -1; + } + + return FileSync(file, WAIT_EVENT_UNDO_FILE_SYNC); + } +} + +/* + * Filtering callback used by SYNC_FILTER_REQUEST to forget some requests. + */ +bool +undofile_filetagmatches(const FileTag *tag, const FileTag *candidate) +{ + /* + * We use SYNC_FILTER_REQUEST to forget requests for a given tablespace, + * before removing all undo files in the tablespace. + */ + return tag->rnode.spcNode == candidate->rnode.spcNode; +} + +/* + * Tell the checkpointer to sync a segment file. + */ +void +undofile_request_sync(UndoLogNumber logno, BlockNumber segno, Oid tablespace) +{ + char path[MAXPGPATH]; + FileTag tag; + + INIT_UNDOFILETAG(tag, logno, tablespace, segno); + + /* Try to send to the checkpointer, but if out of space, do it here. */ + if (!RegisterSyncRequest(&tag, SYNC_REQUEST, false)) + { + if (undofile_syncfiletag(&tag, path) < 0) + ereport(data_sync_elevel(ERROR), + (errmsg("could not fsync file \"%s\": %m", path))); + } +} + +/* + * Tell the checkpointer to forget about any sync requests for a given segment + * file, because it's about to go away. + */ +void +undofile_forget_sync(UndoLogNumber logno, BlockNumber segno, Oid tablespace) +{ + FileTag tag; + + INIT_UNDOFILETAG(tag, logno, tablespace, segno); + + /* Send, and keep retrying if out of space. */ + (void) RegisterSyncRequest(&tag, SYNC_FORGET_REQUEST, true); +} + +/* + * Tell the checkpointer to fsync the undo directory in a given tablespace, + * because we have created or renamed files inside it. + */ +void +undofile_request_sync_dir(Oid tablespace) +{ + char path[MAXPGPATH]; + FileTag tag; + + /* We use a special logno and segno to mean "the directory". */ + INIT_UNDOFILETAG(tag, (Oid) InvalidUndoLogNumber, tablespace, + InvalidBlockNumber); + + /* Try to send to the checkpointer, but if out of space, do it here. */ + if (!RegisterSyncRequest(&tag, SYNC_REQUEST, false)) + { + if (undofile_syncfiletag(&tag, path) < 0) + ereport(data_sync_elevel(ERROR), + (errmsg("could not fsync directory \"%s\": %m", path))); + } +} + +/* + * Tell the checkpointer to forget about all sync requests for a given + * tablespace, because it's about to go away. + */ +void +undofile_forget_sync_tablespace(Oid tablespace) +{ + FileTag tag; + + INIT_UNDOFILETAG(tag, (Oid) InvalidUndoLogNumber, tablespace, + InvalidBlockNumber); + + /* + * Tell checkpointer to forget about any request for this tag, and keep + * waiting if there is not enough space. + */ + (void) RegisterSyncRequest(&tag, SYNC_FILTER_REQUEST, true); +} diff --git a/src/backend/storage/sync/sync.c b/src/backend/storage/sync/sync.c index f329c3f..db7b417 100644 --- a/src/backend/storage/sync/sync.c +++ b/src/backend/storage/sync/sync.c @@ -28,6 +28,7 @@ #include "storage/bufmgr.h" #include "storage/ipc.h" #include "storage/md.h" +#include "storage/undofile.h" #include "utils/hsearch.h" #include "utils/memutils.h" #include "utils/inval.h" @@ -96,6 +97,11 @@ static const SyncOps syncsw[] = { .sync_syncfiletag = mdsyncfiletag, .sync_unlinkfiletag = mdunlinkfiletag, .sync_filetagmatches = mdfiletagmatches + }, + /* undo log segment files */ + { + .sync_syncfiletag = undofile_syncfiletag, + .sync_filetagmatches = undofile_filetagmatches } }; diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index 43b9f17..5d9af89 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -25,6 +25,7 @@ #include "access/session.h" #include "access/sysattr.h" #include "access/tableam.h" +#include "access/undolog.h" #include "access/xact.h" #include "access/xlog.h" #include "catalog/catalog.h" @@ -561,6 +562,7 @@ BaseInit(void) InitSync(); smgrinit(); InitBufferPoolAccess(); + UndoLogInit(); } diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index fc46360..296fb77 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -121,6 +121,7 @@ extern int CommitDelay; extern int CommitSiblings; extern char *default_tablespace; extern char *temp_tablespaces; +extern char *undo_tablespaces; extern bool ignore_checksum_failure; extern bool synchronize_seqscans; @@ -3668,6 +3669,17 @@ static struct config_string ConfigureNamesString[] = }, { + {"undo_tablespaces", PGC_USERSET, CLIENT_CONN_STATEMENT, + gettext_noop("Sets the tablespace(s) to use for undo logs."), + NULL, + GUC_LIST_INPUT | GUC_LIST_QUOTE + }, + &undo_tablespaces, + "", + check_undo_tablespaces, assign_undo_tablespaces, NULL + }, + + { {"dynamic_library_path", PGC_SUSET, CLIENT_CONN_OTHER, gettext_noop("Sets the path for dynamically loadable modules."), gettext_noop("If a dynamically loadable module needs to be opened and " diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 04d77ad..bbcbdfd 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -210,11 +210,13 @@ static const char *const subdirs[] = { "pg_snapshots", "pg_subtrans", "pg_twophase", + "pg_undo", "pg_multixact", "pg_multixact/members", "pg_multixact/offsets", "base", "base/1", + "base/undo", "pg_replslot", "pg_tblspc", "pg_stat", diff --git a/src/bin/pg_checksums/pg_checksums.c b/src/bin/pg_checksums/pg_checksums.c index 8c00ec9..8e83be9 100644 --- a/src/bin/pg_checksums/pg_checksums.c +++ b/src/bin/pg_checksums/pg_checksums.c @@ -167,7 +167,7 @@ skipfile(const char *fn) } static void -scan_file(const char *fn, BlockNumber segmentno) +scan_file(const char *fn, BlockNumber first_blkno) { PGAlignedBlock buf; PageHeader header = (PageHeader) buf.data; @@ -208,7 +208,7 @@ scan_file(const char *fn, BlockNumber segmentno) if (PageIsNew(header)) continue; - csum = pg_checksum_page(buf.data, blockno + segmentno * RELSEG_SIZE); + csum = pg_checksum_page(buf.data, blockno + first_blkno); current_size += r; if (mode == PG_MODE_CHECK) { @@ -310,7 +310,7 @@ scan_directory(const char *basedir, const char *subdir, bool sizeonly) char fnonly[MAXPGPATH]; char *forkpath, *segmentpath; - BlockNumber segmentno = 0; + BlockNumber first_blkno; if (skipfile(de->d_name)) continue; @@ -325,15 +325,22 @@ scan_directory(const char *basedir, const char *subdir, bool sizeonly) segmentpath = strchr(fnonly, '.'); if (segmentpath != NULL) { + char *end; + *segmentpath++ = '\0'; - segmentno = atoi(segmentpath); - if (segmentno == 0) + if (strstr(segmentpath, "undo")) + first_blkno = strtol(segmentpath, &end, 16) / BLCKSZ; + else + first_blkno = strtol(segmentpath, &end, 10) * RELSEG_SIZE; + if (*end != '\0') { - pg_log_error("invalid segment number %d in file name \"%s\"", - segmentno, fn); + pg_log_error("invalid segment number in file name \"%s\"", + fn); exit(1); } } + else + first_blkno = 0; forkpath = strchr(fnonly, '_'); if (forkpath != NULL) @@ -350,7 +357,7 @@ scan_directory(const char *basedir, const char *subdir, bool sizeonly) * the items in the data folder. */ if (!sizeonly) - scan_file(fn, segmentno); + scan_file(fn, first_blkno); } #ifndef WIN32 else if (S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode)) diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c index ff0f8ea..ad96fe7 100644 --- a/src/bin/pg_resetwal/pg_resetwal.c +++ b/src/bin/pg_resetwal/pg_resetwal.c @@ -80,6 +80,7 @@ static bool ReadControlFile(void); static void GuessControlValues(void); static void PrintControlValues(bool guessed); static void PrintNewControlValues(void); +static void AdjustRedoLocation(const char *DataDir); static void RewriteControlFile(void); static void FindEndOfXLOG(void); static void KillExistingXLOG(void); @@ -510,6 +511,7 @@ main(int argc, char *argv[]) /* * Else, do the dirty deed. */ + AdjustRedoLocation(DataDir); RewriteControlFile(); KillExistingXLOG(); KillExistingArchiveStatus(); @@ -890,6 +892,80 @@ PrintNewControlValues(void) /* + * Compute the new redo, and move the pg_undo file to match if necessary. + * Rather than renaming it, we'll create a new copy, so that a failure that + * occurs before the controlfile is rewritten won't be fatal. + */ +static void +AdjustRedoLocation(const char *DataDir) +{ + uint64 old_redo = ControlFile.checkPointCopy.redo; + char old_pg_undo_path[MAXPGPATH]; + char new_pg_undo_path[MAXPGPATH]; + int old_fd; + int new_fd; + ssize_t nread; + ssize_t nwritten; + char buffer[1024]; + + /* + * Adjust fields as needed to force an empty XLOG starting at + * newXlogSegNo. + */ + XLogSegNoOffsetToRecPtr(newXlogSegNo, SizeOfXLogLongPHD, WalSegSz, + ControlFile.checkPointCopy.redo); + + /* If the redo location didn't move, we don't need to do anything. */ + if (old_redo == ControlFile.checkPointCopy.redo) + return; + + /* + * Otherwise we copy the pg_undo file, because its name must match the redo + * location. + */ + snprintf(old_pg_undo_path, + sizeof(old_pg_undo_path), + "pg_undo/%016" INT64_MODIFIER "X", + old_redo); + snprintf(new_pg_undo_path, + sizeof(new_pg_undo_path), + "pg_undo/%016" INT64_MODIFIER "X", + ControlFile.checkPointCopy.redo); + old_fd = open(old_pg_undo_path, O_RDONLY, 0); + if (old_fd < 0) + { + pg_log_error("could not open \"%s\": %m", old_pg_undo_path); + exit(1); + } + new_fd = open(new_pg_undo_path, O_RDWR | O_CREAT, 0644); + if (new_fd < 0) + { + pg_log_error("could not create \"%s\": %m", new_pg_undo_path); + exit(1); + } + while ((nread = read(old_fd, buffer, sizeof(buffer))) > 0) + { + do + { + nwritten = write(new_fd, buffer, nread); + if (nwritten < 0) + { + pg_log_error("could not write to \"%s\": %m", new_pg_undo_path); + exit(1); + } + nread -= nwritten; + } while (nread > 0); + } + if (nread < 0) + { + pg_log_error("could not read from \"%s\": %m", old_pg_undo_path); + exit(1); + } + close(old_fd); + close(new_fd); +} + +/* * Write out the new pg_control file. */ static void diff --git a/src/bin/pg_upgrade/Makefile b/src/bin/pg_upgrade/Makefile index 2cb829a..82c8033 100644 --- a/src/bin/pg_upgrade/Makefile +++ b/src/bin/pg_upgrade/Makefile @@ -9,7 +9,7 @@ include $(top_builddir)/src/Makefile.global OBJS = check.o controldata.o dump.o exec.o file.o function.o info.o \ option.o parallel.o pg_upgrade.o relfilenode.o server.o \ - tablespace.o util.o version.o $(WIN32RES) + tablespace.o undo.o util.o version.o $(WIN32RES) override CPPFLAGS := -DDLSUFFIX=\"$(DLSUFFIX)\" -I$(srcdir) -I$(libpq_srcdir) $(CPPFLAGS) LDFLAGS_INTERNAL += -L$(top_builddir)/src/fe_utils -lpgfeutils $(libpq_pgport) diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 617270f..4a431dc 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -21,6 +21,7 @@ static void check_locale_and_encoding(DbInfo *olddb, DbInfo *newdb); static bool equivalent_locale(int category, const char *loca, const char *locb); static void check_is_install_user(ClusterInfo *cluster); static void check_proper_datallowconn(ClusterInfo *cluster); +static void check_for_undo_data(ClusterInfo *cluster); static void check_for_prepared_transactions(ClusterInfo *cluster); static void check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster); static void check_for_tables_with_oids(ClusterInfo *cluster); @@ -97,6 +98,7 @@ check_and_dump_old_cluster(bool live_check) */ check_is_install_user(&old_cluster); check_proper_datallowconn(&old_cluster); + check_for_undo_data(&old_cluster); check_for_prepared_transactions(&old_cluster); check_for_reg_data_type_usage(&old_cluster); check_for_isn_and_int8_passing_mismatch(&old_cluster); @@ -171,6 +173,7 @@ check_new_cluster(void) check_is_install_user(&new_cluster); + check_for_undo_data(&new_cluster); check_for_prepared_transactions(&new_cluster); } @@ -801,6 +804,46 @@ check_for_prepared_transactions(ClusterInfo *cluster) /* + * check_for_live_undo_data() + * + * Make sure there are no live undo records (aborted transactions that have + * not been rolled back, or committed transactions whose undo data has not + * yet been discarded). + */ +static void +check_for_undo_data(ClusterInfo *cluster) +{ + PGresult *res; + PGconn *conn; + + if (GET_MAJOR_VERSION(old_cluster.major_version) < 1300) + return; + + conn = connectToServer(cluster, "template1"); + prep_status("Checking for undo data"); + + res = executeQueryOrDie(conn, + "SELECT * " + "FROM pg_catalog.pg_stat_undo_logs " + "WHERE discard != insert"); + + if (PQntuples(res) != 0) + { + if (cluster == &old_cluster) + pg_fatal("The source cluster contains live undo data\n"); + else + pg_fatal("The target cluster contains live undo data\n"); + } + + PQclear(res); + + PQfinish(conn); + + check_ok(); +} + + +/* * check_for_isn_and_int8_passing_mismatch() * * contrib/isn relies on data type int8, and in 8.4 int8 can now be passed diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index 3823641..523e86e 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -59,6 +59,7 @@ get_control_data(ClusterInfo *cluster, bool live_check) bool got_date_is_int = false; bool got_data_checksum_version = false; bool got_cluster_state = false; + bool got_redo_location = false; char *lc_collate = NULL; char *lc_ctype = NULL; char *lc_monetary = NULL; @@ -485,6 +486,23 @@ get_control_data(ClusterInfo *cluster, bool live_check) cluster->controldata.data_checksum_version = str2uint(p); got_data_checksum_version = true; } + else if ((p = strstr(bufin, "Latest checkpoint's REDO location:")) != NULL) + { + uint32 hi; + uint32 lo; + + p = strchr(p, ':'); + + if (p == NULL || strlen(p) <= 1) + pg_fatal("%d: controldata retrieval problem\n", __LINE__); + + p++; /* remove ':' char */ + + if (sscanf(p, "%X/%X", &hi, &lo) != 2) + pg_fatal("%d: controldata cannot parse REDO location\n", __LINE__); + cluster->controldata.redo_location = (((uint64) hi) << 32) | lo; + got_redo_location = true; + } } pclose(output); @@ -528,6 +546,13 @@ get_control_data(ClusterInfo *cluster, bool live_check) } } + /* + * If we used pg_resetwal instead of pg_controldata, there is no REDO + * location. + */ + if (!got_redo_location) + cluster->controldata.redo_location = 0; + /* verify that we got all the mandatory pg_control data */ if (!got_xid || !got_oid || !got_multi || diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 0363309..f23451a 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -351,6 +351,10 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_clog"); else check_single_dir(pg_data, "pg_xact"); + + /* pg_undo is new in v13 */ + if (GET_MAJOR_VERSION(cluster->major_version) >= 1300) + check_single_dir(pg_data, "pg_undo"); } diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index d1975aa..09b786f 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -139,6 +139,8 @@ main(int argc, char **argv) /* New now using xids of the old system */ + merge_undo_logs(); + /* -- NEW -- */ start_postmaster(&new_cluster, true); diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h index 5d31750..d0d93c0 100644 --- a/src/bin/pg_upgrade/pg_upgrade.h +++ b/src/bin/pg_upgrade/pg_upgrade.h @@ -227,6 +227,7 @@ typedef struct bool date_is_int; bool float8_pass_by_value; bool data_checksum_version; + uint64 redo_location; } ControlData; /* @@ -465,3 +466,7 @@ void parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr char *old_pgdata, char *new_pgdata, char *old_tablespace); bool reap_child(bool wait_for_child); + +/* undo.c */ + +void merge_undo_logs(void); diff --git a/src/bin/pg_upgrade/undo.c b/src/bin/pg_upgrade/undo.c new file mode 100644 index 0000000..48397b0 --- /dev/null +++ b/src/bin/pg_upgrade/undo.c @@ -0,0 +1,292 @@ +/* + * undo.c + * + * Support for upgrading undo logs.\ + * Copyright (c) 2019, PostgreSQL Global Development Group + * src/bin/pg_upgrade/undo.c + */ + + +#include "postgres_fe.h" +#include "pg_upgrade.h" +#include "access/undolog.h" + +/* + * The relevant parts of UndoLogMetaDataData, in a version-independent format. + */ +typedef struct +{ + UndoLogNumber logno; + UndoLogOffset discard; + UndoLogStatus status; + UndoLogCategory category; + Oid tablespace; +} UndoLogInfo; + +/* + * Read the header of a pg_undo file and extract basic information. If the + * format of the header changes in later versions, this may need to change + * depending on "cluster". + */ +static void +read_pg_undo_header(int fd, ClusterInfo *cluster, UndoLogNumber *low_logno, + UndoLogNumber *next_logno, UndoLogNumber *num_logs) +{ + pg_crc32c crc; + + /* Read the header, much like StartupUndoLogs(). */ + if (read(fd, low_logno, sizeof(*low_logno)) != sizeof(*low_logno) || + read(fd, next_logno, sizeof(*next_logno)) != sizeof(*next_logno) || + read(fd, num_logs, sizeof(*num_logs)) != sizeof(*num_logs) || + read(fd, &crc, sizeof(crc)) != sizeof(crc)) + pg_fatal("pg_undo file is corrupted or cannot be read\n"); +} + +/* + * Read a single UndoLogMetaData object. If the format changes in later + * versions, this may need to change to be able to read different structs + * depending on "cluster". + */ +static void +read_one_undo_log(int fd, ClusterInfo *cluster, UndoLogInfo *info) +{ + UndoLogMetaData meta_data; + int rc; + + rc = read(fd, &meta_data, sizeof(meta_data)); + if (rc < 0) + pg_fatal("could not read undo log meta-data: %m"); + else if (rc != sizeof(meta_data)) + pg_fatal("could not read undo log meta-data: expect %zu bytes but read only %d bytes", + sizeof(meta_data), rc); + + info->logno = meta_data.logno; + info->category = meta_data.category; + info->tablespace = meta_data.tablespace; + info->discard = meta_data.discard; + info->status = meta_data.status; +} + +static void +merge_undo_log(UndoLogInfo *logs, UndoLogNumber *num_logs, + const UndoLogInfo *info) +{ + UndoLogNumber i; + + /* Do we already have an entry for this logno? */ + for (i = 0; i < *num_logs; ++i) + { + if (logs[i].logno == info->logno) + { + /* + * Take the highest discard offset, so that any pointers that + * originated in either cluster appear to be discarded. + */ + if (logs[i].discard < info->discard) + logs[i].discard = info->discard; + + /* + * Take the highest status so that entirely discarded logs trump + * active logs. + */ + StaticAssertStmt(UNDO_LOG_STATUS_ACTIVE < UNDO_LOG_STATUS_FULL, + "undo log status out of order"); + StaticAssertStmt(UNDO_LOG_STATUS_FULL < UNDO_LOG_STATUS_DISCARDED, + "undo log status out of order"); + if (logs[i].status < info->status) + logs[i].status = info->status; + + /* + * Take the most persistent persistence level. While we could + * just convert them all to permanent and it wouldn't hurt, it's + * probably a better idea to keep about the same number of each + * persistence level, so that a system that has stabilized with + * those numbers will continue to be stable after the upgrade (ie + * not suddenly need to create more undo logs of different + * levels). The most permanent is the best choice, because TEMP + * undo logs might be rewound in future. + */ + StaticAssertStmt(UNDO_PERMANENT < UNDO_UNLOGGED, + "undo log persistent out of order"); + StaticAssertStmt(UNDO_UNLOGGED < UNDO_TEMP, + "undo log persistent out of order"); + if (logs[i].status > info->status) + logs[i].status = info->status; + + /* + * Take the highest tablespace OID. The choice of 'highest' is + * arbitrary (we don't really expect the new cluster to have more + * than one log), but it seems useful to preserve the distribution + * of tablespaces from the old cluster for stability, as above. + */ + if (logs[i].tablespace < info->tablespace) + logs[i].tablespace = info->tablespace; + break; + } + } + + /* Otherwise create a new entry. */ + logs[*num_logs++] = *info; +} + +/* + * We need to merge the old undo logs and the new undo logs. We know that + * there is no live undo data (see check_for_live_undo_data()), but we need to + * make sure that any undo record pointers that exist in the old OR new + * cluster appear as discarded. That is, any log numbers that are entirely + * discarded in either cluster appear as entirely discarded, and we retain + * the higher of the discard pointers in any log that is active. This is + * mostly a theoretical concern for now, but perhaps a future release will be + * able to create higher undo record pointers during initdb than the old + * cluster had, so let's use an algorithm that doesn't make any assumptions + * about that. + */ +void +merge_undo_logs(void) +{ + char old_pg_undo_path[MAXPGPATH]; + char new_pg_undo_path[MAXPGPATH]; + UndoLogInfo *logs; + UndoLogNumber num_logs; + UndoLogNumber num_old_logs; + UndoLogNumber old_low_logno; + UndoLogNumber old_next_logno; + UndoLogNumber num_new_logs; + UndoLogNumber new_low_logno; + UndoLogNumber new_next_logno; + UndoLogNumber i; + int old_fd; + int new_fd; + pg_crc32c crc; + + /* If the old cluster has no undo logs, there is nothing to do */ + if (GET_MAJOR_VERSION(old_cluster.major_version) < 1300) + return; + + /* + * Open the pg_undo files corresponding to the old and new redo locations. + * First, we'll reload pg_controldata output, so that we have up-to-date + * redo locations. + */ + get_control_data(&old_cluster, true); + get_control_data(&new_cluster, true); + snprintf(old_pg_undo_path, + sizeof(old_pg_undo_path), + "%s/pg_undo/%016" INT64_MODIFIER "X", + old_cluster.pgdata, + old_cluster.controldata.redo_location); + snprintf(new_pg_undo_path, + sizeof(new_pg_undo_path), + "%s/pg_undo/%016" INT64_MODIFIER "X", + new_cluster.pgdata, + new_cluster.controldata.redo_location); + old_fd = open(old_pg_undo_path, O_RDONLY, 0); + if (old_fd < 0) + pg_fatal("could not open file \"%s\": %m\n", old_pg_undo_path); + new_fd = open(new_pg_undo_path, O_RDWR, 0); + if (new_fd < 0) + pg_fatal("could not open file \"%s\": %m\n", new_pg_undo_path); + + /* Read the headers */ + read_pg_undo_header(old_fd, &old_cluster, &old_low_logno, &old_next_logno, &num_old_logs); + read_pg_undo_header(new_fd, &new_cluster, &new_low_logno, &new_next_logno, &num_new_logs); + + /* Allocate workspace that is sure to be enough for the merged set */ + logs = malloc(sizeof(*logs) * (num_old_logs + num_new_logs)); + if (logs == NULL) + { + pg_fatal("out of memory\n"); + exit(1); + } + num_logs = 0; + + /* + * Anything below the "low" logno has been entirely discarded, so we'll + * take the higher of the two values. Likewise, the "next" log number to + * allocate should be the higher of the two. + */ + new_low_logno = Max(old_low_logno, new_low_logno); + new_next_logno = Max(old_next_logno, new_next_logno); + + /* Merge in the old logs */ + while (num_old_logs > 0) + { + UndoLogInfo info; + + read_one_undo_log(old_fd, &old_cluster, &info); + merge_undo_log(logs, &num_logs, &info); + --num_old_logs; + } + + /* Merge in the new logs */ + while (num_new_logs > 0) + { + UndoLogInfo info; + + read_one_undo_log(new_fd, &old_cluster, &info); + merge_undo_log(logs, &num_logs, &info); + --num_new_logs; + } + + close(old_fd); + + /* Now write out the new file, much like CheckPointUndoLogs() */ + if (ftruncate(new_fd, 0) < 0) + pg_fatal("could not truncate file \"%s\": %m", new_pg_undo_path); + if (lseek(new_fd, SEEK_SET, 0) < 0) + pg_fatal("could not seek to start of file \"%s\": %m", new_pg_undo_path); + + /* Compute header checksum */ + INIT_CRC32C(crc); + COMP_CRC32C(crc, &new_low_logno, sizeof(new_low_logno)); + COMP_CRC32C(crc, &new_next_logno, sizeof(new_next_logno)); + COMP_CRC32C(crc, &num_logs, sizeof(num_logs)); + FIN_CRC32C(crc); + + /* Write out the header */ + if ((write(new_fd, &new_low_logno, sizeof(new_low_logno)) != sizeof(new_low_logno)) || + (write(new_fd, &new_next_logno, sizeof(new_next_logno)) != sizeof(new_next_logno)) || + (write(new_fd, &num_logs, sizeof(num_logs)) != sizeof(num_logs)) || + (write(new_fd, &crc, sizeof(crc)) != sizeof(crc))) + pg_fatal("could not write to file \"%s\": %m", new_pg_undo_path); + + /* Write out the undo logs */ + INIT_CRC32C(crc); + for (i = 0; i < num_logs; ++i) + { + UndoLogMetaData meta_data; + UndoLogInfo *info = &logs[i]; + UndoLogOffset end; + + memset(&meta_data, 0, sizeof(meta_data)); + meta_data.logno = info->logno; + + /* + * Round the discard offset up so that it points to the first byte in + * a segment, and assign that to all three offsets. That means there + * is no logical data, and there are no physical files. + */ + end = ((info->discard + UndoLogSegmentSize - 1) / UndoLogSegmentSize) + * UndoLogSegmentSize; + meta_data.unlogged.insert = meta_data.discard = meta_data.end = end; + + /* + * We have whatever was the highest status (though it probably + * wouldn't hurt if we set them all to ACTIVE). + */ + meta_data.status = info->status; + + + if (write(new_fd, &meta_data, sizeof(meta_data)) != sizeof(meta_data)) + pg_fatal("could not write to file \"%s\": %m", new_pg_undo_path); + + COMP_CRC32C(crc, &meta_data, sizeof(meta_data)); + } + FIN_CRC32C(crc); + + if (write(new_fd, &crc, sizeof(crc)) != sizeof(crc)) + pg_fatal("could not write to file \"%s\": %m", new_pg_undo_path); + + close(new_fd); + free(logs); +} diff --git a/src/bin/pg_waldump/rmgrdesc.c b/src/bin/pg_waldump/rmgrdesc.c index 852d8ca..938150d 100644 --- a/src/bin/pg_waldump/rmgrdesc.c +++ b/src/bin/pg_waldump/rmgrdesc.c @@ -20,6 +20,7 @@ #include "access/nbtxlog.h" #include "access/rmgr.h" #include "access/spgxlog.h" +#include "access/undolog_xlog.h" #include "access/xact.h" #include "access/xlog_internal.h" #include "catalog/storage_xlog.h" diff --git a/src/include/access/rmgrlist.h b/src/include/access/rmgrlist.h index 3c0db2c..6945e3e 100644 --- a/src/include/access/rmgrlist.h +++ b/src/include/access/rmgrlist.h @@ -47,3 +47,4 @@ PG_RMGR(RM_COMMIT_TS_ID, "CommitTs", commit_ts_redo, commit_ts_desc, commit_ts_i PG_RMGR(RM_REPLORIGIN_ID, "ReplicationOrigin", replorigin_redo, replorigin_desc, replorigin_identify, NULL, NULL, NULL) PG_RMGR(RM_GENERIC_ID, "Generic", generic_redo, generic_desc, generic_identify, NULL, NULL, generic_mask) PG_RMGR(RM_LOGICALMSG_ID, "LogicalMessage", logicalmsg_redo, logicalmsg_desc, logicalmsg_identify, NULL, NULL, NULL) +PG_RMGR(RM_UNDOLOG_ID, "UndoLog", undolog_redo, undolog_desc, undolog_identify, NULL, NULL, NULL) diff --git a/src/include/access/session.h b/src/include/access/session.h index 8fba568..da0770e 100644 --- a/src/include/access/session.h +++ b/src/include/access/session.h @@ -17,6 +17,9 @@ /* Avoid including typcache.h */ struct SharedRecordTypmodRegistry; +/* Avoid including undolog.h */ +struct UndoLogSlot; + /* * A struct encapsulating some elements of a user's session. For now this * manages state that applies to parallel query, but it principle it could @@ -27,6 +30,10 @@ typedef struct Session dsm_segment *segment; /* The session-scoped DSM segment. */ dsa_area *area; /* The session-scoped DSA area. */ + /* State managed by undolog.c. */ + struct UndoLogSlot *attached_undo_slots[4]; /* UndoLogCategories */ + bool need_to_choose_undo_tablespace; + /* State managed by typcache.c. */ struct SharedRecordTypmodRegistry *shared_typmod_registry; dshash_table *shared_record_table; diff --git a/src/include/access/undolog.h b/src/include/access/undolog.h new file mode 100644 index 0000000..c4a6b29 --- /dev/null +++ b/src/include/access/undolog.h @@ -0,0 +1,489 @@ +/*------------------------------------------------------------------------- + * + * undolog.h + * + * PostgreSQL undo log manager. This module is responsible for lifecycle + * management of undo logs and backing files, associating undo logs with + * backends, allocating and managing space within undo logs. + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/undolog.h + * + *------------------------------------------------------------------------- + */ +#ifndef UNDOLOG_H +#define UNDOLOG_H + +#include "access/transam.h" +#include "access/xlogreader.h" +#include "catalog/database_internal.h" +#include "catalog/pg_class.h" +#include "common/relpath.h" +#include "storage/bufpage.h" + +#ifndef FRONTEND +#include "storage/lwlock.h" +#endif + +/* The type used to identify an undo log and position within it. */ +typedef uint64 UndoRecPtr; + +/* The type used for undo record lengths. */ +typedef uint16 UndoRecordSize; + +/* Undo log statuses. */ +typedef enum +{ + UNDO_LOG_STATUS_UNUSED = 0, + UNDO_LOG_STATUS_ACTIVE, + UNDO_LOG_STATUS_FULL, + UNDO_LOG_STATUS_DISCARDED +} UndoLogStatus; + +/* + * Undo log categories. These correspond to the different persistence levels + * of relations so that we can discard unlogged and temporary undo data + * wholesale in some circumstance. We also have a separate category for + * 'shared' records that are not associated with a single transactions. Since + * they might live longer than the transaction that created them, and since we + * prefer to avoid interleaving records that don't belong to the same + * transaction, we keep them separate. + */ +typedef enum +{ + UNDO_PERMANENT = 0, + UNDO_UNLOGGED = 1, + UNDO_TEMP = 2, + UNDO_SHARED = 3 +} UndoLogCategory; + +#define UndoLogCategories 4 + +/* + * Convert from relpersistence ('p', 'u', 't') to an UndoLogCategory + * enumerator. + */ +#define UndoLogCategoryForRelPersistence(rp) \ + ((rp) == RELPERSISTENCE_PERMANENT ? UNDO_PERMANENT : \ + (rp) == RELPERSISTENCE_UNLOGGED ? UNDO_UNLOGGED : UNDO_TEMP) + +/* + * Convert from UndoLogCategory to a relpersistence value. There is no + * relpersistence level for UNDO_SHARED, but the only use of this macro is to + * pass a value to ReadBufferWithoutRelcache, which cares only about detecting + * RELPERSISTENCE_TEMP. XXX There must be a better way. + */ +#define RelPersistenceForUndoLogCategory(up) \ + ((up) == UNDO_PERMANENT ? RELPERSISTENCE_PERMANENT : \ + (up) == UNDO_UNLOGGED ? RELPERSISTENCE_UNLOGGED : \ + (up) == UNDO_SHARED ? RELPERSISTENCE_PERMANENT : \ + RELPERSISTENCE_TEMP) + +/* + * Get the appropriate UndoLogCategory value from a Relation. + */ +#define UndoLogCategoryForRelation(rel) \ + (UndoLogCategoryForRelPersistence((rel)->rd_rel->relpersistence)) + +/* Type for offsets within undo logs */ +typedef uint64 UndoLogOffset; + +/* printf-family format string for UndoRecPtr. */ +#define UndoRecPtrFormat "%016" INT64_MODIFIER "X" + +/* printf-family format string for UndoLogOffset. */ +#define UndoLogOffsetFormat UINT64_FORMAT + +/* Number of blocks of BLCKSZ in an undo log segment file. 128 = 1MB. */ +#define UNDOSEG_SIZE 128 + +/* Size of an undo log segment file in bytes. */ +#define UndoLogSegmentSize ((size_t) BLCKSZ * UNDOSEG_SIZE) + +/* The width of an undo log number in bits. 24 allows for 16.7m logs. */ +#define UndoLogNumberBits 24 + +/* The maximum valid undo log number. */ +#define MaxUndoLogNumber ((1 << UndoLogNumberBits) - 1) + +/* The width of an undo log offset in bits. 40 allows for 1TB per log.*/ +#define UndoLogOffsetBits (64 - UndoLogNumberBits) + +/* Special value for undo record pointer which indicates that it is invalid. */ +#define InvalidUndoRecPtr ((UndoRecPtr) 0) + +/* End-of-list value when building linked lists of undo logs. */ +#define InvalidUndoLogNumber -1 + +/* + * The maximum amount of data that can be stored in an undo log. Can be set + * artificially low to test full log behavior. + */ +#define UndoLogMaxSize ((UndoLogOffset) 1 << UndoLogOffsetBits) + +/* Type for numbering undo logs. */ +typedef int UndoLogNumber; + +/* Extract the undo log number from an UndoRecPtr. */ +#define UndoRecPtrGetLogNo(urp) \ + ((urp) >> UndoLogOffsetBits) + +/* Extract the offset from an UndoRecPtr. */ +#define UndoRecPtrGetOffset(urp) \ + ((urp) & ((UINT64CONST(1) << UndoLogOffsetBits) - 1)) + +/* Make an UndoRecPtr from an log number and offset. */ +#define MakeUndoRecPtr(logno, offset) \ + (((uint64) (logno) << UndoLogOffsetBits) | (offset)) + +/* The number of unusable bytes in the header of each block. */ +#define UndoLogBlockHeaderSize SizeOfPageHeaderData + +/* The number of usable bytes we can store per block. */ +#define UndoLogUsableBytesPerPage (BLCKSZ - UndoLogBlockHeaderSize) + +/* Length of undo checkpoint filename */ +#define UNDO_CHECKPOINT_FILENAME_LENGTH 16 + +/* + * UndoRecPtrIsValid + * True iff undoRecPtr is valid. + */ +#define UndoRecPtrIsValid(undoRecPtr) \ + ((bool) ((UndoRecPtr) (undoRecPtr) != InvalidUndoRecPtr)) + +/* Extract the relnode for an undo log. */ +#define UndoRecPtrGetRelNode(urp) \ + UndoRecPtrGetLogNo(urp) + +/* The only valid fork number for undo log buffers. */ +#define UndoLogForkNum MAIN_FORKNUM + +/* Compute the block number that holds a given UndoRecPtr. */ +#define UndoRecPtrGetBlockNum(urp) \ + (UndoRecPtrGetOffset(urp) / BLCKSZ) + +/* Compute the offset of a given UndoRecPtr in the page that holds it. */ +#define UndoRecPtrGetPageOffset(urp) \ + (UndoRecPtrGetOffset(urp) % BLCKSZ) + +/* Compare two undo checkpoint files to find the oldest file. */ +#define UndoCheckPointFilenamePrecedes(file1, file2) \ + (strcmp(file1, file2) < 0) + +/* What is the offset of the i'th non-header byte? */ +#define UndoLogOffsetFromUsableByteNo(i) \ + (((i) / UndoLogUsableBytesPerPage) * BLCKSZ + \ + UndoLogBlockHeaderSize + \ + ((i) % UndoLogUsableBytesPerPage)) + +/* How many non-header bytes are there before a given offset? */ +#define UndoLogOffsetToUsableByteNo(offset) \ + (((offset) % BLCKSZ - UndoLogBlockHeaderSize) + \ + ((offset) / BLCKSZ) * UndoLogUsableBytesPerPage) + +/* Add 'n' usable bytes to offset stepping over headers to find new offset. */ +#define UndoLogOffsetPlusUsableBytes(offset, n) \ + UndoLogOffsetFromUsableByteNo(UndoLogOffsetToUsableByteNo(offset) + (n)) + +/* Populate a RelFileNode from an UndoRecPtr. */ +#define UndoRecPtrAssignRelFileNode(rfn, urp) \ + do \ + { \ + (rfn).spcNode = UndoLogNumberGetTablespace(UndoRecPtrGetLogNo(urp)); \ + (rfn).dbNode = UndoDbOid; \ + (rfn).relNode = UndoRecPtrGetRelNode(urp); \ + } while (false); + +/* + * Properties of an undo log that don't have explicit WAL records logging + * their changes, to reduce WAL volume. Instead, they change incrementally + * whenever data is inserted as a result of other WAL records. Since the + * values recorded in an online checkpoint may be out of the sync (ie not the + * correct values as at the redo LSN), these are backed up in buffer data on + * first change after each checkpoint. + */ +typedef struct UndoLogUnloggedMetaData +{ + UndoLogOffset insert; /* next insertion point (head) */ + UndoLogOffset last_xact_start; /* last transaction's first byte in this log */ + UndoLogOffset this_xact_start; /* this transaction's first byte in this log */ + TransactionId xid; /* currently attached/writing xid */ + + /* + * Below two variable are used during recovery when transaction's undo + * records are split across undo logs. Replay of switch will restore + * these two undo record pointers which will be reset on next allocation + * during recovery. */ + UndoRecPtr prevlog_xact_start; /* Transaction's start undo record pointer + * in the previous log. */ + UndoRecPtr prevlog_last_urp; /* Transaction's last undo record pointer in + * the previous log. */ +} UndoLogUnloggedMetaData; + +/* + * Control metadata for an active undo log. Lives in shared memory inside an + * UndoLogSlot object, but also written to disk during checkpoints. + */ +typedef struct UndoLogMetaData +{ + /* Members that are not managed by explicit WAL logs. */ + UndoLogUnloggedMetaData unlogged; + + /* Members that are fixed for the lifetime of the undo log. */ + UndoLogNumber logno; + Oid tablespace; + UndoLogCategory category; + + /* Members that are changed by explicit WAL records. */ + UndoLogStatus status; + UndoLogOffset end; /* one past end of highest segment */ + UndoLogOffset discard; /* oldest data needed (tail) */ +} UndoLogMetaData; + +/* + * Context used to hold undo log state across all the undo log insertions + * corresponding to a single WAL record. + */ +typedef struct UndoLogAllocContext +{ + UndoLogCategory category; + UndoRecPtr try_location; + XLogReaderState *xlog_record; + UndoLogNumber recovery_logno; + uint8 recovery_block_id; + bool new_shared_record_set; + + /* + * The maximum number of undo logs that a single WAL record could insert + * into, modifying its unlogged meta data. Typically the number is 1, but + * it might touch a couple or more in rare cases where space runs out. + */ +#define MAX_META_DATA_IMAGES 4 + int num_meta_data_images; + struct + { + UndoLogNumber logno; + UndoLogUnloggedMetaData data; + } meta_data_images[MAX_META_DATA_IMAGES]; +} UndoLogAllocContext; + +#ifndef FRONTEND + +/* + * The in-memory control object for an undo log. We have a fixed-sized array + * of these. + */ +typedef struct UndoLogSlot +{ + /* + * Protected by UndoLogLock and 'mutex'. Both must be held to steal this + * slot for another undolog. Either may be held to prevent that from + * happening. + */ + UndoLogNumber logno; /* InvalidUndoLogNumber for unused slots */ + + /* Protected by UndoLogLock. */ + UndoLogNumber next_free; /* link for active unattached undo logs */ + + /* Protected by 'mutex'. */ + LWLock mutex; + UndoLogMetaData meta; /* current meta-data */ + pid_t pid; /* InvalidPid for unattached */ + + /* Protected by 'discard_lock'. State used by undo workers. */ + FullTransactionId wait_fxmin; /* trigger for processing this log again */ + UndoRecPtr oldest_data; + LWLock discard_lock; /* prevents discarding while reading */ + LWLock discard_update_lock; /* block updaters during discard */ +} UndoLogSlot; + +extern UndoLogSlot *UndoLogGetSlot(UndoLogNumber logno, bool missing_ok); +extern UndoLogSlot *UndoLogNextSlot(UndoLogSlot *slot); +extern bool AmAttachedToUndoLogSlot(UndoLogSlot *slot); +extern UndoRecPtr UndoLogGetOldestRecord(UndoLogNumber logno, bool *full); + +/* + * Each backend maintains a small hash table mapping undo log numbers to + * UndoLogSlot objects in shared memory. + * + * We also cache the tablespace, category and a recently observed discard + * pointer here, since we need fast access to those. We could also reach them + * via slot->meta, but they can't be accessed without locking (since the + * UndoLogSlot object might be recycled if the log is entirely discard). + * Since tablespace and category are constant for lifetime of the undo log + * number, and the discard pointer only travels in one direction, there is no + * cache invalidation problem to worry about. + */ +typedef struct UndoLogTableEntry +{ + UndoLogNumber number; + UndoLogSlot *slot; + Oid tablespace; + UndoLogCategory category; + UndoRecPtr recent_discard; + char status; /* used by simplehash */ +} UndoLogTableEntry; + +/* + * Instantiate fast inline hash table access functions. We use an identity + * hash function for speed, since we already have integers and don't expect + * many collisions. + */ +#define SH_PREFIX undologtable +#define SH_ELEMENT_TYPE UndoLogTableEntry +#define SH_KEY_TYPE UndoLogNumber +#define SH_KEY number +#define SH_HASH_KEY(tb, key) (key) +#define SH_EQUAL(tb, a, b) ((a) == (b)) +#define SH_SCOPE static inline +#define SH_DECLARE +#define SH_DEFINE +#include "lib/simplehash.h" + +extern PGDLLIMPORT undologtable_hash *undologtable_cache; + +/* + * Find or create an UndoLogTableGetEntry for this log number. This is used + * only for fast look-ups of tablespace and persistence. + */ +static pg_attribute_always_inline UndoLogTableEntry * +UndoLogGetTableEntry(UndoLogNumber logno) +{ + UndoLogTableEntry *entry; + + /* Fast path. */ + entry = undologtable_lookup(undologtable_cache, logno); + if (likely(entry)) + return entry; + + /* Slow path: force cache entry to be created. */ + UndoLogGetSlot(logno, false); + entry = undologtable_lookup(undologtable_cache, logno); + + return entry; +} + +/* + * Look up the tablespace for an undo log in our cache. + */ +static inline Oid +UndoLogNumberGetTablespace(UndoLogNumber logno) +{ + return UndoLogGetTableEntry(logno)->tablespace; +} + +static inline Oid +UndoRecPtrGetTablespace(UndoRecPtr urp) +{ + return UndoLogNumberGetTablespace(UndoRecPtrGetLogNo(urp)); +} + +/* + * Look up the category for an undo log in our cache. + */ +static inline UndoLogCategory +UndoLogNumberGetCategory(UndoLogNumber logno) +{ + return UndoLogGetTableEntry(logno)->category; +} + +static inline UndoLogCategory +UndoRecPtrGetCategory(UndoRecPtr urp) +{ + return UndoLogNumberGetCategory(UndoRecPtrGetLogNo(urp)); +} + +#endif + +/* Space management. */ +extern void UndoLogBeginInsert(UndoLogAllocContext *context, + UndoLogCategory category, + XLogReaderState *xlog_record); +extern void UndoLogRegister(UndoLogAllocContext *context, + uint8 block_id, + UndoLogNumber logno); +extern UndoRecPtr UndoLogAllocate(UndoLogAllocContext *context, + uint16 size, + bool *need_xact_header, + UndoRecPtr *last_xact_start, + UndoRecPtr *prevlog_xact_start, + UndoRecPtr *prevlog_insert_urp); +extern UndoRecPtr UndoLogAllocateInRecovery(UndoLogAllocContext *context, + TransactionId xid, + uint16 size, + bool *need_xact_header, + UndoRecPtr *last_xact_start, + UndoRecPtr *prevlog_xact_start, + UndoRecPtr *prevlog_last_urp); +extern void UndoLogAdvance(UndoLogAllocContext *context, size_t size); +extern void UndoLogAdvanceFinal(UndoRecPtr insertion_point, size_t size); +extern bool UndoLogDiscard(UndoRecPtr discard_point, TransactionId xid); +extern bool UndoLogRecPtrIsDiscardedSlowPath(UndoRecPtr pointer); + +#ifndef FRONTEND + +/* + * Check if an undo log pointer is discarded. + */ +static inline bool +UndoRecPtrIsDiscarded(UndoRecPtr pointer) +{ + UndoLogNumber logno = UndoRecPtrGetLogNo(pointer); + UndoRecPtr recent_discard; + + /* See if we can answer the question without acquiring any locks. */ + recent_discard = UndoLogGetTableEntry(logno)->recent_discard; + if (likely(recent_discard > pointer)) + return true; + + /* + * It might be discarded or not, but we'll need to do a bit more work to + * find out. + */ + return UndoLogRecPtrIsDiscardedSlowPath(pointer); +} + +#endif + +/* Initialization interfaces. */ +extern void StartupUndoLogs(XLogRecPtr checkPointRedo); +extern void UndoLogShmemInit(void); +extern Size UndoLogShmemSize(void); +extern void UndoLogInit(void); +extern void UndoLogDirectory(Oid tablespace, char *path); +extern void UndoLogSegmentPath(UndoLogNumber logno, int segno, Oid tablespace, + char *path); +extern void ResetUndoLogs(UndoLogCategory category); + +/* Interface use by tablespace.c. */ +extern bool DropUndoLogsInTablespace(Oid tablespace); + +/* GUC interfaces. */ +extern void assign_undo_tablespaces(const char *newval, void *extra); + +/* Checkpointing interfaces. */ +extern void CheckPointUndoLogs(XLogRecPtr checkPointRedo, + XLogRecPtr priorCheckPointRedo); + +/* File sync request management. */ + + +extern UndoRecPtr UndoLogGetLastXactStartPoint(UndoLogNumber logno); +extern UndoRecPtr UndoLogGetNextInsertPtr(UndoLogNumber logno); +extern void UndoLogSwitchSetPrevLogInfo(UndoLogNumber logno, + UndoRecPtr prevlog_last_urp, + UndoRecPtr prevlog_xact_start); +extern void UndoLogSetLSN(XLogRecPtr lsn); +void UndoLogNewSegment(UndoLogNumber logno, Oid tablespace, int segno); +/* Redo interface. */ +extern void undolog_redo(XLogReaderState *record); +/* Discard the undo logs for temp tables */ +extern void TempUndoDiscard(UndoLogNumber); + +/* Test-only interfacing. */ +extern void UndoLogDetachFull(void); + +#endif diff --git a/src/include/access/undolog_xlog.h b/src/include/access/undolog_xlog.h new file mode 100644 index 0000000..aa9003b --- /dev/null +++ b/src/include/access/undolog_xlog.h @@ -0,0 +1,62 @@ +/*------------------------------------------------------------------------- + * + * undolog_xlog.h + * undo log access XLOG definitions. + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/undolog_xlog.h + * + *------------------------------------------------------------------------- + */ +#ifndef UNDOLOG_XLOG_H +#define UNDOLOG_XLOG_H + +#include "access/undolog.h" +#include "access/xlogreader.h" +#include "lib/stringinfo.h" + +/* XLOG records */ +#define XLOG_UNDOLOG_CREATE 0x00 +#define XLOG_UNDOLOG_EXTEND 0x10 +#define XLOG_UNDOLOG_DISCARD 0x20 +#define XLOG_UNDOLOG_SWITCH 0x30 + +/* Create a new undo log. */ +typedef struct xl_undolog_create +{ + UndoLogNumber logno; + Oid tablespace; + UndoLogCategory category; +} xl_undolog_create; + +/* Extend an undo log by adding a new segment. */ +typedef struct xl_undolog_extend +{ + UndoLogNumber logno; + UndoLogOffset end; +} xl_undolog_extend; + +/* Discard space, and possibly destroy or recycle undo log segments. */ +typedef struct xl_undolog_discard +{ + UndoLogNumber logno; + UndoLogOffset discard; + UndoLogOffset end; + TransactionId latestxid; /* latest xid whose undolog are discarded. */ + bool entirely_discarded; +} xl_undolog_discard; + +/* Switch undo log. */ +typedef struct xl_undolog_switch +{ + UndoLogNumber logno; + UndoRecPtr prevlog_xact_start; + UndoRecPtr prevlog_last_urp; +} xl_undolog_switch; + +extern void undolog_desc(StringInfo buf,XLogReaderState *record); +extern const char *undolog_identify(uint8 info); + +#endif diff --git a/src/include/access/xlogutils.h b/src/include/access/xlogutils.h index 4105b59..4db68f1 100644 --- a/src/include/access/xlogutils.h +++ b/src/include/access/xlogutils.h @@ -44,6 +44,20 @@ extern XLogRedoAction XLogReadBufferForRedoExtended(XLogReaderState *record, extern Buffer XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum, BlockNumber blkno, ReadBufferMode mode); +extern bool XLogFindBlockId(XLogReaderState *record, + RelFileNode rnode, + ForkNumber forknum, + BlockNumber blockno, + uint8 *block_id); + +extern XLogRedoAction XLogReadBufferForRedoBlock(XLogReaderState *record, + RelFileNode rnode, + ForkNumber forknum, + BlockNumber blockno, + ReadBufferMode mode, + bool get_cleanup_lock, + Buffer *buf); + extern Relation CreateFakeRelcacheEntry(RelFileNode rnode); extern void FreeFakeRelcacheEntry(Relation fakerel); diff --git a/src/include/catalog/database_internal.h b/src/include/catalog/database_internal.h new file mode 100644 index 0000000..a2b3a12 --- /dev/null +++ b/src/include/catalog/database_internal.h @@ -0,0 +1,21 @@ +/*------------------------------------------------------------------------- + * + * database_internal.h + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/database_internal.h + * + *------------------------------------------------------------------------- + */ +#ifndef DATABASE_INTERNAL_H +#define DATABASE_INTERNAL_H + +/* + * We use this header to define the OIDs of pseudo-database OIDs used in + * buffer tags to hold system data. + */ +#define UndoDbOid 9 + +#endif /* DATABASE_INTERNAL_H */ diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index 0902dce..de475cb 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -10701,4 +10701,11 @@ proname => 'pg_partition_root', prorettype => 'regclass', proargtypes => 'regclass', prosrc => 'pg_partition_root' }, +# undo logs +{ oid => '5032', descr => 'list undo logs', + proname => 'pg_stat_get_undo_logs', procost => '1', prorows => '10', proretset => 't', + prorettype => 'record', proargtypes => '', + proallargtypes => '{oid,text,text,text,text,text,xid,int4,text}', proargmodes => '{o,o,o,o,o,o,o,o,o}', + proargnames => '{logno,category,tablespace,discard,insert,end,xid,pid,status}', prosrc => 'pg_stat_get_undo_logs' }, + ] diff --git a/src/include/pgstat.h b/src/include/pgstat.h index 0a3ad3a..1936c5d 100644 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@ -934,6 +934,13 @@ typedef enum WAIT_EVENT_TWOPHASE_FILE_READ, WAIT_EVENT_TWOPHASE_FILE_SYNC, WAIT_EVENT_TWOPHASE_FILE_WRITE, + WAIT_EVENT_UNDO_CHECKPOINT_READ, + WAIT_EVENT_UNDO_CHECKPOINT_SYNC, + WAIT_EVENT_UNDO_CHECKPOINT_WRITE, + WAIT_EVENT_UNDO_FILE_READ, + WAIT_EVENT_UNDO_FILE_WRITE, + WAIT_EVENT_UNDO_FILE_FLUSH, + WAIT_EVENT_UNDO_FILE_SYNC, WAIT_EVENT_WALSENDER_TIMELINE_HISTORY_READ, WAIT_EVENT_WAL_BOOTSTRAP_SYNC, WAIT_EVENT_WAL_BOOTSTRAP_WRITE, diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index 509f4b7..a04190a 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -37,8 +37,9 @@ typedef enum BufferAccessStrategyType typedef enum { RBM_NORMAL, /* Normal read */ - RBM_ZERO_AND_LOCK, /* Don't read from disk, caller will - * initialize. Also locks the page. */ + RBM_ZERO, /* Don't read from disk, caller will + * initialize. */ + RBM_ZERO_AND_LOCK, /* Like RBM_ZERO, but also locks the page. */ RBM_ZERO_AND_CLEANUP_LOCK, /* Like RBM_ZERO_AND_LOCK, but locks the page * in "cleanup" mode */ RBM_ZERO_ON_ERROR, /* Read, but return an all-zeros page on error */ @@ -170,7 +171,10 @@ extern Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BufferAccessStrategy strategy); extern Buffer ReadBufferWithoutRelcache(RelFileNode rnode, ForkNumber forkNum, BlockNumber blockNum, - ReadBufferMode mode, BufferAccessStrategy strategy); + ReadBufferMode mode, BufferAccessStrategy strategy, + char relpersistence); +extern void ForgetBuffer(RelFileNode rnode, ForkNumber forkNum, + BlockNumber blockNum); extern void ReleaseBuffer(Buffer buffer); extern void UnlockReleaseBuffer(Buffer buffer); extern void MarkBufferDirty(Buffer buffer); @@ -227,6 +231,10 @@ extern void AtProcExit_LocalBuffers(void); extern void TestForOldSnapshot_impl(Snapshot snapshot, Relation relation); +/* in localbuf.c */ +extern void ForgetLocalBuffer(RelFileNode rnode, ForkNumber forkNum, + BlockNumber blockNum); + /* in freelist.c */ extern BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype); extern void FreeAccessStrategy(BufferAccessStrategy strategy); diff --git a/src/include/storage/fd.h b/src/include/storage/fd.h index d2a8c52..b215201 100644 --- a/src/include/storage/fd.h +++ b/src/include/storage/fd.h @@ -143,6 +143,7 @@ extern int pg_fsync_writethrough(int fd); extern int pg_fdatasync(int fd); extern void pg_flush_data(int fd, off_t offset, off_t amount); extern void fsync_fname(const char *fname, bool isdir); +extern int fsync_fname_ext(const char *fname, bool isdir, bool perm, int elevel); extern int durable_rename(const char *oldfile, const char *newfile, int loglevel); extern int durable_unlink(const char *fname, int loglevel); extern int durable_link_or_rename(const char *oldfile, const char *newfile, int loglevel); diff --git a/src/include/storage/lwlock.h b/src/include/storage/lwlock.h index 08e0dc8..4abb344 100644 --- a/src/include/storage/lwlock.h +++ b/src/include/storage/lwlock.h @@ -220,7 +220,10 @@ typedef enum BuiltinTrancheIds LWTRANCHE_TBM, LWTRANCHE_PARALLEL_APPEND, LWTRANCHE_SXACT, - LWTRANCHE_FIRST_USER_DEFINED + LWTRANCHE_UNDOLOG, + LWTRANCHE_UNDODISCARD, + LWTRANCHE_REWIND, + LWTRANCHE_FIRST_USER_DEFINED, } BuiltinTrancheIds; /* diff --git a/src/include/storage/smgr.h b/src/include/storage/smgr.h index d286c8c..0fd3b75 100644 --- a/src/include/storage/smgr.h +++ b/src/include/storage/smgr.h @@ -70,6 +70,9 @@ typedef struct SMgrRelationData int md_num_open_segs[MAX_FORKNUM + 1]; struct _MdfdVec *md_seg_fds[MAX_FORKNUM + 1]; + /* For use by implementations. */ + void *private_data; + /* if unowned, list link in list of all unowned SMgrRelations */ dlist_node node; } SMgrRelationData; diff --git a/src/include/storage/sync.h b/src/include/storage/sync.h index 16428c5..59f1da9 100644 --- a/src/include/storage/sync.h +++ b/src/include/storage/sync.h @@ -34,7 +34,8 @@ typedef enum SyncRequestType */ typedef enum SyncRequestHandler { - SYNC_HANDLER_MD = 0 /* md smgr */ + SYNC_HANDLER_MD = 0, /* md smgr */ + SYNC_HANDLER_UNDO = 1 /* undo smgr */ } SyncRequestHandler; /* diff --git a/src/include/storage/undofile.h b/src/include/storage/undofile.h new file mode 100644 index 0000000..a5ec30f --- /dev/null +++ b/src/include/storage/undofile.h @@ -0,0 +1,59 @@ +/*------------------------------------------------------------------------- + * + * undofile.h + * undo storage manager public interface declarations. + * + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/undofile.h + * + *------------------------------------------------------------------------- + */ +#ifndef UNDOFILE_H +#define UNDOFILE_H + +#include "access/undolog.h" +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "storage/smgr.h" +#include "storage/sync.h" + +extern void undofile_init(void); +extern void undofile_shutdown(void); +extern void undofile_open(SMgrRelation reln); +extern void undofile_close(SMgrRelation reln, ForkNumber forknum); +extern void undofile_create(SMgrRelation reln, ForkNumber forknum, + bool isRedo); +extern bool undofile_exists(SMgrRelation reln, ForkNumber forknum); +extern void undofile_unlink(RelFileNodeBackend rnode, ForkNumber forknum, + bool isRedo); +extern void undofile_extend(SMgrRelation reln, ForkNumber forknum, + BlockNumber blocknum, char *buffer, bool skipFsync); +extern void undofile_prefetch(SMgrRelation reln, ForkNumber forknum, + BlockNumber blocknum); +extern void undofile_read(SMgrRelation reln, ForkNumber forknum, + BlockNumber blocknum, char *buffer); +extern void undofile_write(SMgrRelation reln, ForkNumber forknum, + BlockNumber blocknum, char *buffer, bool skipFsync); +extern void undofile_writeback(SMgrRelation reln, ForkNumber forknum, + BlockNumber blocknum, BlockNumber nblocks); +extern BlockNumber undofile_nblocks(SMgrRelation reln, ForkNumber forknum); +extern void undofile_truncate(SMgrRelation reln, ForkNumber forknum, + BlockNumber nblocks); +extern void undofile_immedsync(SMgrRelation reln, ForkNumber forknum); + +/* Callbacks used by sync.c. */ +extern int undofile_syncfiletag(const FileTag *tag, char *path); +extern bool undofile_filetagmatches(const FileTag *tag, const FileTag *candidate); + +/* Management of checkpointer requests. */ +extern void undofile_request_sync(UndoLogNumber logno, BlockNumber segno, + Oid tablespace); +extern void undofile_forget_sync(UndoLogNumber logno, BlockNumber segno, + Oid tablespace); +extern void undofile_forget_sync_tablespace(Oid tablespace); +extern void undofile_request_sync_dir(Oid tablespace); + +#endif /* UNDOFILE_H */ diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h index e709177..84639ee 100644 --- a/src/include/utils/guc.h +++ b/src/include/utils/guc.h @@ -431,6 +431,8 @@ extern void GUC_check_errcode(int sqlerrcode); extern bool check_default_tablespace(char **newval, void **extra, GucSource source); extern bool check_temp_tablespaces(char **newval, void **extra, GucSource source); extern void assign_temp_tablespaces(const char *newval, void *extra); +extern bool check_undo_tablespaces(char **newval, void **extra, GucSource source); +extern void assign_undo_tablespaces(const char *newval, void *extra); /* in catalog/namespace.c */ extern bool check_search_path(char **newval, void **extra, GucSource source); diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index 210e9cd..7098461 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -2010,6 +2010,16 @@ pg_stat_sys_tables| SELECT pg_stat_all_tables.relid, pg_stat_all_tables.autoanalyze_count FROM pg_stat_all_tables WHERE ((pg_stat_all_tables.schemaname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) OR (pg_stat_all_tables.schemaname ~ '^pg_toast'::text)); +pg_stat_undo_logs| SELECT pg_stat_get_undo_logs.logno, + pg_stat_get_undo_logs.category, + pg_stat_get_undo_logs.tablespace, + pg_stat_get_undo_logs.discard, + pg_stat_get_undo_logs.insert, + pg_stat_get_undo_logs."end", + pg_stat_get_undo_logs.xid, + pg_stat_get_undo_logs.pid, + pg_stat_get_undo_logs.status + FROM pg_stat_get_undo_logs() pg_stat_get_undo_logs(logno, category, tablespace, discard, insert, "end", xid, pid, status); pg_stat_user_functions| SELECT p.oid AS funcid, n.nspname AS schemaname, p.proname AS funcname, -- 1.8.3.1 [application/octet-stream] 0004-Allow-WAL-record-data-on-first-modification-after-a-.patch (2.1K, ../../CAA4eK1+McY0qGaak0AHyzdgAn+F6dyxcpDwp9ifGg=1WVDadeQ@mail.gmail.com/5-0004-Allow-WAL-record-data-on-first-modification-after-a-.patch) download | inline diff: From 3d3565b64e2c2fd3a47c6fbdfa42d542923d44d4 Mon Sep 17 00:00:00 2001 From: Thomas Munro <[email protected]> Date: Sat, 12 Jan 2019 02:17:02 +1300 Subject: [PATCH 04/13] Allow WAL record data on first modification after a checkpoint. Provide a way to attach data to WAL record conditionally, so that it is included only if this turns out to the be first modification to a given block after a checkpoint. This will be used to record undo log meta-data, to avoid a data synchronization problem with online checkpoints. Author: Thomas Munro Reviewed-by: Discussion: --- src/backend/access/transam/xloginsert.c | 15 +++++++++++++++ src/include/access/xloginsert.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/backend/access/transam/xloginsert.c b/src/backend/access/transam/xloginsert.c index 3ec67d4..001d7cb 100644 --- a/src/backend/access/transam/xloginsert.c +++ b/src/backend/access/transam/xloginsert.c @@ -565,6 +565,21 @@ XLogRecordAssemble(RmgrId rmid, uint8 info, needs_data = false; else if ((regbuf->flags & REGBUF_KEEP_DATA) != 0) needs_data = true; + else if ((regbuf->flags & REGBUF_KEEP_DATA_AFTER_CP) != 0) + { + XLogRecPtr page_lsn = PageGetLSN(regbuf->page); + + needs_data = (page_lsn <= RedoRecPtr); + if (!needs_data) + { + /* + * XLogInsertRecord() will detect if our view of the latest + * checkpoint's RedoRecPtr is out of date. + */ + if (*fpw_lsn == InvalidXLogRecPtr || page_lsn < *fpw_lsn) + *fpw_lsn = page_lsn; + } + } else needs_data = !needs_backup; diff --git a/src/include/access/xloginsert.h b/src/include/access/xloginsert.h index df24089..22b388c 100644 --- a/src/include/access/xloginsert.h +++ b/src/include/access/xloginsert.h @@ -37,6 +37,8 @@ * will be skipped) */ #define REGBUF_KEEP_DATA 0x10 /* include data even if a full-page image * is taken */ +#define REGBUF_KEEP_DATA_AFTER_CP 0x20 /* include data on the first + * modification after a checkpoint */ /* prototypes for public functions in xloginsert.c: */ extern void XLogBeginInsert(void); -- 1.8.3.1 [application/octet-stream] 0005-Add-prefetch-support-for-the-undo-log.patch (7.9K, ../../CAA4eK1+McY0qGaak0AHyzdgAn+F6dyxcpDwp9ifGg=1WVDadeQ@mail.gmail.com/6-0005-Add-prefetch-support-for-the-undo-log.patch) download | inline diff: From 8e9190898eb0cd12afea72f7ad89c192d5943e60 Mon Sep 17 00:00:00 2001 From: Dilip Kumar <[email protected]> Date: Wed, 24 Apr 2019 14:36:28 +0530 Subject: [PATCH 05/13] Add prefetch support for the undo log Add prefetching function for undo smgr and also provide mechanism to prefetch without relcache. Dilip Kumar --- src/backend/postmaster/pgstat.c | 3 ++ src/backend/storage/buffer/bufmgr.c | 101 ++++++++++++++++++++++++------------ src/backend/storage/smgr/undofile.c | 13 ++++- src/include/pgstat.h | 1 + src/include/storage/bufmgr.h | 4 ++ 5 files changed, 87 insertions(+), 35 deletions(-) diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index c742861..d8dc0cc 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -4079,6 +4079,9 @@ pgstat_get_wait_io(WaitEventIO w) case WAIT_EVENT_UNDO_CHECKPOINT_SYNC: event_name = "UndoCheckpointSync"; break; + case WAIT_EVENT_UNDO_FILE_PREFETCH: + event_name = "UndoFilePrefetch"; + break; case WAIT_EVENT_UNDO_FILE_READ: event_name = "UndoFileRead"; break; diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 2b1d606..5abf42e 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -520,14 +520,57 @@ ComputeIoConcurrency(int io_concurrency, double *target) return (new_prefetch_pages >= 0.0 && new_prefetch_pages < (double) INT_MAX); } +#ifdef USE_PREFETCH /* - * PrefetchBuffer -- initiate asynchronous read of a block of a relation + * PrefetchBufferGuts -- Guts of prefetching a buffer. * * This is named by analogy to ReadBuffer but doesn't actually allocate a * buffer. Instead it tries to ensure that a future ReadBuffer for the given * block will not be delayed by the I/O. Prefetching is optional. * No-op if prefetching isn't compiled in. */ +static void +PrefetchBufferGuts(RelFileNode rnode, SMgrRelation smgr, ForkNumber forkNum, + BlockNumber blockNum) +{ + BufferTag newTag; /* identity of requested block */ + uint32 newHash; /* hash value for newTag */ + LWLock *newPartitionLock; /* buffer partition lock for it */ + int buf_id; + + /* create a tag so we can lookup the buffer */ + INIT_BUFFERTAG(newTag, rnode, forkNum, blockNum); + + /* determine its hash code and partition lock ID */ + newHash = BufTableHashCode(&newTag); + newPartitionLock = BufMappingPartitionLock(newHash); + + /* see if the block is in the buffer pool already */ + LWLockAcquire(newPartitionLock, LW_SHARED); + buf_id = BufTableLookup(&newTag, newHash); + LWLockRelease(newPartitionLock); + + /* If not in buffers, initiate prefetch */ + if (buf_id < 0) + smgrprefetch(smgr, forkNum, blockNum); + + /* + * If the block *is* in buffers, we do nothing. This is not really + * ideal: the block might be just about to be evicted, which would be + * stupid since we know we are going to need it soon. But the only + * easy answer is to bump the usage_count, which does not seem like a + * great solution: when the caller does ultimately touch the block, + * usage_count would get bumped again, resulting in too much + * favoritism for blocks that are involved in a prefetch sequence. A + * real fix would involve some additional per-buffer state, and it's + * not clear that there's enough of a problem to justify that. + */ +} +#endif /* USE_PREFETCH */ + +/* + * PrefetchBuffer -- initiate asynchronous read of a block of a relation + */ void PrefetchBuffer(Relation reln, ForkNumber forkNum, BlockNumber blockNum) { @@ -550,42 +593,32 @@ PrefetchBuffer(Relation reln, ForkNumber forkNum, BlockNumber blockNum) LocalPrefetchBuffer(reln->rd_smgr, forkNum, blockNum); } else - { - BufferTag newTag; /* identity of requested block */ - uint32 newHash; /* hash value for newTag */ - LWLock *newPartitionLock; /* buffer partition lock for it */ - int buf_id; - - /* create a tag so we can lookup the buffer */ - INIT_BUFFERTAG(newTag, reln->rd_smgr->smgr_rnode.node, - forkNum, blockNum); - - /* determine its hash code and partition lock ID */ - newHash = BufTableHashCode(&newTag); - newPartitionLock = BufMappingPartitionLock(newHash); - - /* see if the block is in the buffer pool already */ - LWLockAcquire(newPartitionLock, LW_SHARED); - buf_id = BufTableLookup(&newTag, newHash); - LWLockRelease(newPartitionLock); + PrefetchBufferGuts(reln->rd_smgr->smgr_rnode.node, reln->rd_smgr, + forkNum, blockNum); +#endif /* USE_PREFETCH */ +} - /* If not in buffers, initiate prefetch */ - if (buf_id < 0) - smgrprefetch(reln->rd_smgr, forkNum, blockNum); +/* + * PrefetchBufferWithoutRelcache -- like PrefetchBuffer but doesn't need a + * relcache entry for the relation. + */ +void +PrefetchBufferWithoutRelcache(RelFileNode rnode, ForkNumber forkNum, + BlockNumber blockNum, char relpersistence) +{ +#ifdef USE_PREFETCH + SMgrRelation smgr = smgropen(rnode, + relpersistence == RELPERSISTENCE_TEMP + ? MyBackendId : InvalidBackendId); - /* - * If the block *is* in buffers, we do nothing. This is not really - * ideal: the block might be just about to be evicted, which would be - * stupid since we know we are going to need it soon. But the only - * easy answer is to bump the usage_count, which does not seem like a - * great solution: when the caller does ultimately touch the block, - * usage_count would get bumped again, resulting in too much - * favoritism for blocks that are involved in a prefetch sequence. A - * real fix would involve some additional per-buffer state, and it's - * not clear that there's enough of a problem to justify that. - */ + if (relpersistence == RELPERSISTENCE_TEMP) + { + /* pass it off to localbuf.c */ + LocalPrefetchBuffer(smgr, forkNum, blockNum); } -#endif /* USE_PREFETCH */ + else + PrefetchBufferGuts(rnode, smgr, forkNum, blockNum); +#endif /* USE_PREFETCH */ } diff --git a/src/backend/storage/smgr/undofile.c b/src/backend/storage/smgr/undofile.c index 04d4514..3be0f5e 100644 --- a/src/backend/storage/smgr/undofile.c +++ b/src/backend/storage/smgr/undofile.c @@ -119,7 +119,18 @@ undofile_extend(SMgrRelation reln, ForkNumber forknum, void undofile_prefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum) { - elog(ERROR, "undofile_prefetch is not supported"); +#ifdef USE_PREFETCH + File file; + off_t seekpos; + + Assert(forknum == MAIN_FORKNUM); + file = undofile_get_segment_file(reln, blocknum / UNDOSEG_SIZE); + seekpos = (off_t) BLCKSZ * (blocknum % ((BlockNumber) UNDOSEG_SIZE)); + + Assert(seekpos < (off_t) BLCKSZ * UNDOSEG_SIZE); + + (void) FilePrefetch(file, seekpos, BLCKSZ, WAIT_EVENT_UNDO_FILE_PREFETCH); +#endif /* USE_PREFETCH */ } void diff --git a/src/include/pgstat.h b/src/include/pgstat.h index 1936c5d..2fff673 100644 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@ -937,6 +937,7 @@ typedef enum WAIT_EVENT_UNDO_CHECKPOINT_READ, WAIT_EVENT_UNDO_CHECKPOINT_SYNC, WAIT_EVENT_UNDO_CHECKPOINT_WRITE, + WAIT_EVENT_UNDO_FILE_PREFETCH, WAIT_EVENT_UNDO_FILE_READ, WAIT_EVENT_UNDO_FILE_WRITE, WAIT_EVENT_UNDO_FILE_FLUSH, diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index a04190a..5c0ed58 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -165,6 +165,10 @@ extern PGDLLIMPORT int32 *LocalRefCount; extern bool ComputeIoConcurrency(int io_concurrency, double *target); extern void PrefetchBuffer(Relation reln, ForkNumber forkNum, BlockNumber blockNum); +extern void PrefetchBufferWithoutRelcache(RelFileNode rnode, + ForkNumber forkNum, + BlockNumber blockNum, + char relpersistence); extern Buffer ReadBuffer(Relation reln, BlockNumber blockNum); extern Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, -- 1.8.3.1 [application/octet-stream] 0006-Defect-and-enhancement-in-multi-log-support.patch (4.2K, ../../CAA4eK1+McY0qGaak0AHyzdgAn+F6dyxcpDwp9ifGg=1WVDadeQ@mail.gmail.com/7-0006-Defect-and-enhancement-in-multi-log-support.patch) download | inline diff: From 126e9cc8da96ffa1a0c9842961db78b96d920917 Mon Sep 17 00:00:00 2001 From: Dilip Kumar <[email protected]> Date: Fri, 7 Jun 2019 15:03:37 +0530 Subject: [PATCH 06/13] Defect and enhancement in multi-log support --- src/backend/access/undo/undolog.c | 18 +++++++++--------- src/include/access/undolog.h | 20 ++++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/backend/access/undo/undolog.c b/src/backend/access/undo/undolog.c index f2e0272..b5502f2 100644 --- a/src/backend/access/undo/undolog.c +++ b/src/backend/access/undo/undolog.c @@ -940,11 +940,11 @@ UndoLogAllocateInRecovery(UndoLogAllocContext *context, context->recovery_logno = slot->logno; /* Read log switch information from meta and reset it. */ - *prevlog_xact_start = slot->meta.unlogged.prevlog_xact_start; - *prevlog_last_urp = slot->meta.unlogged.prevlog_last_urp; + *prevlog_xact_start = slot->meta.prevlog_xact_start; + *prevlog_last_urp = slot->meta.prevlog_last_urp; - slot->meta.unlogged.prevlog_xact_start = InvalidUndoRecPtr; - slot->meta.unlogged.prevlog_last_urp = InvalidUndoRecPtr; + slot->meta.prevlog_xact_start = InvalidUndoRecPtr; + slot->meta.prevlog_last_urp = InvalidUndoRecPtr; return MakeUndoRecPtr(slot->logno, slot->meta.unlogged.insert); } @@ -1284,8 +1284,8 @@ UndoLogSwitchSetPrevLogInfo(UndoLogNumber logno, UndoRecPtr prevlog_xact_start, Assert(AmAttachedToUndoLogSlot(slot)); LWLockAcquire(&slot->mutex, LW_EXCLUSIVE); - slot->meta.unlogged.prevlog_xact_start = prevlog_last_urp; - slot->meta.unlogged.prevlog_last_urp = prevlog_last_urp; + slot->meta.prevlog_xact_start = prevlog_xact_start; + slot->meta.prevlog_last_urp = prevlog_last_urp; LWLockRelease(&slot->mutex); /* Wal log the log switch. */ @@ -1293,7 +1293,7 @@ UndoLogSwitchSetPrevLogInfo(UndoLogNumber logno, UndoRecPtr prevlog_xact_start, xl_undolog_switch xlrec; xlrec.logno = logno; - xlrec.prevlog_xact_start = prevlog_last_urp; + xlrec.prevlog_xact_start = prevlog_xact_start; xlrec.prevlog_last_urp = prevlog_xact_start; XLogBeginInsert(); @@ -2571,8 +2571,8 @@ undolog_xlog_switch(XLogReaderState *record) * Restore the log switch information in the MyUndoLogState this will be * reset by following UndoLogAllocateDuringRecovery. */ - slot->meta.unlogged.prevlog_xact_start = xlrec->prevlog_xact_start; - slot->meta.unlogged.prevlog_last_urp = xlrec->prevlog_last_urp; + slot->meta.prevlog_xact_start = xlrec->prevlog_xact_start; + slot->meta.prevlog_last_urp = xlrec->prevlog_last_urp; } void diff --git a/src/include/access/undolog.h b/src/include/access/undolog.h index c4a6b29..1c79c1f 100644 --- a/src/include/access/undolog.h +++ b/src/include/access/undolog.h @@ -211,16 +211,6 @@ typedef struct UndoLogUnloggedMetaData UndoLogOffset last_xact_start; /* last transaction's first byte in this log */ UndoLogOffset this_xact_start; /* this transaction's first byte in this log */ TransactionId xid; /* currently attached/writing xid */ - - /* - * Below two variable are used during recovery when transaction's undo - * records are split across undo logs. Replay of switch will restore - * these two undo record pointers which will be reset on next allocation - * during recovery. */ - UndoRecPtr prevlog_xact_start; /* Transaction's start undo record pointer - * in the previous log. */ - UndoRecPtr prevlog_last_urp; /* Transaction's last undo record pointer in - * the previous log. */ } UndoLogUnloggedMetaData; /* @@ -241,6 +231,16 @@ typedef struct UndoLogMetaData UndoLogStatus status; UndoLogOffset end; /* one past end of highest segment */ UndoLogOffset discard; /* oldest data needed (tail) */ + + /* + * Below two variable are used during recovery when transaction's undo + * records are split across undo logs. Replay of switch will restore + * these two undo record pointers which will be reset on next allocation + * during recovery. */ + UndoRecPtr prevlog_xact_start; /* Transaction's start undo record pointer + * in the previous log. */ + UndoRecPtr prevlog_last_urp; /* Transaction's last undo record pointer in + * the previous log. */ } UndoLogMetaData; /* -- 1.8.3.1 [application/octet-stream] 0007-Provide-interfaces-to-store-and-fetch-undo-records.patch (111.1K, ../../CAA4eK1+McY0qGaak0AHyzdgAn+F6dyxcpDwp9ifGg=1WVDadeQ@mail.gmail.com/8-0007-Provide-interfaces-to-store-and-fetch-undo-records.patch) download | inline diff: From b4c7d6041f2d7f46814e8bdd3d37e22d5e9c3c05 Mon Sep 17 00:00:00 2001 From: Dilip Kumar <[email protected]> Date: Thu, 2 May 2019 11:28:13 +0530 Subject: [PATCH 07/13] Provide interfaces to store and fetch undo records. Add the capability to form undo records and store them in undo logs. We also provide the capability to fetch the undo records. This layer will use undo-log-storage to reserve the space for the undo records and buffer management routines to write and read the undo records. Undo records are stored in sequential order in the undo log. Each undo record consists of a variable length header, tuple data, and payload information. The undo records are stored without any sort of alignment padding and a undo record can span across multiple pages. The undo records for a transaction can span across multiple undo logs. Author: Dilip Kumar with contributions from Robert Haas, Amit Kapila, Thomas Munro, Vignesh C and Rafia Sabih Reviewed-by: Earlier version of this patch is reviewed by Amit Kapila Tested-by: Neha Sharma Discussion: https://www.postgresql.org/message-id/CAFiTN-uVxxopn0UZ64%3DF-sydbETBbGjWapnBikNo1%3DXv78UeFw%40mail.gmail.com --- src/backend/access/undo/Makefile | 2 +- src/backend/access/undo/README.undointerface | 29 + src/backend/access/undo/undoaccess.c | 1754 ++++++++++++++++++++++++++ src/backend/access/undo/undorecord.c | 1051 +++++++++++++++ src/backend/storage/page/bufpage.c | 28 + src/include/access/transam.h | 1 + src/include/access/undoaccess.h | 121 ++ src/include/access/undolog.h | 10 +- src/include/access/undorecord.h | 279 ++++ src/include/storage/bufpage.h | 40 + 10 files changed, 3311 insertions(+), 4 deletions(-) create mode 100644 src/backend/access/undo/README.undointerface create mode 100644 src/backend/access/undo/undoaccess.c create mode 100755 src/backend/access/undo/undorecord.c create mode 100644 src/include/access/undoaccess.h create mode 100644 src/include/access/undorecord.h diff --git a/src/backend/access/undo/Makefile b/src/backend/access/undo/Makefile index 219c696..049a416 100644 --- a/src/backend/access/undo/Makefile +++ b/src/backend/access/undo/Makefile @@ -12,6 +12,6 @@ subdir = src/backend/access/undo top_builddir = ../../../.. include $(top_builddir)/src/Makefile.global -OBJS = undolog.o +OBJS = undoaccess.o undolog.o undorecord.o include $(top_srcdir)/src/backend/common.mk diff --git a/src/backend/access/undo/README.undointerface b/src/backend/access/undo/README.undointerface new file mode 100644 index 0000000..41e2c0e --- /dev/null +++ b/src/backend/access/undo/README.undointerface @@ -0,0 +1,29 @@ +Undo record interface layer +--------------------------- +This is the next layer which sits on top of the undo log storage, which will +provide an interface for prepare, insert, or fetch the undo records. This +layer will use undo-log-storage to reserve the space for the undo records +and buffer management routine to write and read the undo records. + +Writing an undo record +---------------------- +To prepare an undo record, first, it will allocate required space using +undo log storage module. Next, it will pin and lock the required buffers and +return an undo record pointer where it will insert the record. Finally, it +calls the Insert routine for final insertion of prepared record. Additionally, +there is a mechanism for multi-insert, wherein multiple records are prepared +and inserted at a time. + +Fetching and undo record +------------------------ +To fetch an undo record, a caller must provide a valid undo record pointer. +Optionally, the caller can provide a callback function with the information of +the block and offset, which will help in faster retrieval of undo record, +otherwise, it has to traverse the undo-chain. + +There is also an interface to bulk fetch the undo records. Where the caller +can provide a TO and FROM undo record pointer and the memory limit for storing +the undo records. This API will return all the undo record between FROM and TO +undo record pointers if they can fit into provided memory limit otherwise, it +return whatever can fit into the memory limit. And, the caller can call it +repeatedly until it fetches all the records. diff --git a/src/backend/access/undo/undoaccess.c b/src/backend/access/undo/undoaccess.c new file mode 100644 index 0000000..a8cf469 --- /dev/null +++ b/src/backend/access/undo/undoaccess.c @@ -0,0 +1,1754 @@ +/*------------------------------------------------------------------------- + * + * undoaccess.c + * entry points for inserting/fetching undo records + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/backend/access/undo/undoaccess.c + * + * NOTES: + * Undo record layout: + * + * Undo records are stored in sequential order in the undo log. Each undo + * record consists of a variable length header, tuple data, and payload + * information. The first undo record of each transaction contains a + * transaction header that points to the next transaction's start header. + * This allows us to discard the entire transaction's log at one-shot rather + * than record-by-record. The callers are not aware of transaction header, + * this is entirely maintained and used by undo record layer. See + * undorecord.h for detailed information about undo record header. + * + * Multiple logs: + * + * It is possible that the undo records for a transaction spans multiple undo + * logs. We need some special handling while inserting them to ensure that + * discard and rollbacks can work sanely. + * + * When the undo record for a transaction gets inserted in the next log then we + * add a transaction header for the first record of the transaction in the new + * log and connect this undo record to the first record of the transaction in + * the next log by updating the "uur_next" field. + * + * We will also keep a previous undo record pointer to the first and last undo + * record of the transaction in the previous log. The last undo record + * location is used find the previous undo record pointer during rollback. + * The first undo record location is used to find the previous transaction + * header which is required to update the undo apply progress. + * ------------------------------------------------------------------------- + */ + +#include "postgres.h" + +#include "access/subtrans.h" +#include "access/transam.h" +#include "access/undorecord.h" +#include "access/undoaccess.h" +#include "access/undolog_xlog.h" +#include "access/xact.h" +#include "access/xlog.h" +#include "access/xlogutils.h" +#include "catalog/pg_tablespace.h" +#include "commands/tablecmds.h" +#include "storage/block.h" +#include "storage/buf.h" +#include "storage/buf_internals.h" +#include "storage/bufmgr.h" +#include "miscadmin.h" + +/* + * Information for compression of the undo records on a page so that we can + * avoid duplicating same values across multiple undo records on a page. + * + * The cid/xid/reloid/rmid information will be added in the undo record header + * in the following cases: + * a) The first undo record of the transaction. + * b) First undo record of the page. + * c) All subsequent record for the transaction which is not the first + * transaction on the page. + * Except above cases, If the rmid/reloid/xid/cid is same in the subsequent + * records this information will not be stored in the record, these information + * will be retrieved from the first undo record of that page. + * If any of the member rmid/reloid/xid/cid has changed, the changed information + * will be stored in the undo record and the remaining information will be + * retrieved from the first complete undo record of the page + */ +UndoCompressionInfo undo_compression_info[UndoLogCategories]; + +/* Prototypes for static functions. */ +static UnpackedUndoRecord *UndoGetOneRecord(UnpackedUndoRecord *urec, + UndoRecPtr urp, RelFileNode rnode, + UndoLogCategory category, + Buffer *prevbuf); +static int UndoRecordPrepareTransInfo(UndoRecordInsertContext *context, + UndoRecPtr xact_urp, int size, int offset); +static void UndoRecordUpdateTransInfo(UndoRecordInsertContext *context, + int idx); +static void UndoRecordPrepareUpdateNext(UndoRecordInsertContext *context, + UndoRecPtr urecptr, UndoRecPtr xact_urp); +static int UndoGetBufferSlot(UndoRecordInsertContext *context, + RelFileNode rnode, BlockNumber blk, + ReadBufferMode rbm); +static uint16 UndoGetPrevRecordLen(UndoRecPtr urp, Buffer input_buffer, + UndoLogCategory category); +static bool UndoSetCommonInfo(UndoCompressionInfo *compressioninfo, + UnpackedUndoRecord *urec, UndoRecPtr urp, + Buffer buffer); + +/* + * Structure to hold the prepared undo information. + */ +struct PreparedUndoSpace +{ + UndoRecPtr urp; /* undo record pointer */ + UnpackedUndoRecord *urec; /* undo record */ + uint16 size; /* undo record size */ + int undo_buffer_idx[MAX_BUFFER_PER_UNDO]; /* undo_buffer array + * index */ +}; + +/* + * This holds undo buffers information required for PreparedUndoSpace during + * prepare undo time. Basically, during prepare time which is called outside + * the critical section we will acquire all necessary undo buffers pin and lock. + * Later, during insert phase we will write actual records into thse buffers. + */ +struct PreparedUndoBuffer +{ + UndoLogNumber logno; /* Undo log number */ + BlockNumber blk; /* block number */ + Buffer buf; /* buffer allocated for the block */ + bool zero; /* new block full of zeroes */ +}; + +/* + * Compute the size of the partial record on the undo page. + * + * Compute the complete record size by uur_info and variable field length + * stored in the page header and then subtract the offset of the record so that + * we can get the exact size of partial record in this page. + */ +static inline Size +UndoPagePartialRecSize(UndoPageHeader phdr) +{ + Size size = UndoRecordHeaderSize(phdr->uur_info); + + /* + * Add length of the variable part and undo length. Now, we know the + * complete length of the undo record. + */ + size += phdr->tuple_len + phdr->payload_len + sizeof(uint16); + + /* + * Subtract the size which is stored in the previous page to get the + * partial record size stored in this page. + */ + size -= phdr->record_offset; + + return size; +} + +/* + * Prepare to update the transaction header + * + * It's a helper function for PrepareUpdateNext and + * PrepareUpdateUndoActionProgress + * + * xact_urp - undo record pointer to be updated. + * size - number of bytes to be updated. + * offset - offset in undo record where to start update. + */ +static int +UndoRecordPrepareTransInfo(UndoRecordInsertContext *context, + UndoRecPtr xact_urp, int size, int offset) +{ + BlockNumber cur_blk; + RelFileNode rnode; + int starting_byte; + int bufidx; + int index = 0; + int remaining_bytes; + XactUndoRecordInfo *xact_info; + + xact_info = &context->xact_urec_info[context->nxact_urec_info]; + + UndoRecPtrAssignRelFileNode(rnode, xact_urp); + cur_blk = UndoRecPtrGetBlockNum(xact_urp); + starting_byte = UndoRecPtrGetPageOffset(xact_urp); + + /* Remaining bytes on the current block. */ + remaining_bytes = BLCKSZ - starting_byte; + + /* + * Is there some byte of the urec_next on the current block, if not then + * start from the next block. + */ + if (remaining_bytes <= offset) + { + cur_blk++; + starting_byte = UndoLogBlockHeaderSize; + starting_byte += (offset - remaining_bytes); + } + else + starting_byte += offset; + + /* + * Set the offset in the first block where we need to start writing, + * during the prepare phase so that during update phase we need not to + * compute it again. + */ + xact_info->offset = starting_byte; + + /* Loop until we have fetched all the buffers in which we need to write. */ + while (size > 0) + { + bufidx = UndoGetBufferSlot(context, rnode, cur_blk, RBM_NORMAL); + + Assert(index < MAX_BUFFER_PER_UNDO); + + xact_info->idx_undo_buffers[index++] = bufidx; + size -= (BLCKSZ - starting_byte); + starting_byte = UndoLogBlockHeaderSize; + cur_blk++; + } + + xact_info->next = InvalidUndoRecPtr; + xact_info->progress = 0; + xact_info->urecptr = xact_urp; + context->nxact_urec_info++; + + return (context->nxact_urec_info - 1); +} + +/* + * Prepare to update the transaction's next undo pointer. + * + * Lock necessary buffer for updating the next of the transaction header. This + * function is called for + * a. Updating the current transaction's start undo record pointer in previous + * transaction's start header. + * b. For multi-log transaction update the start undo record pointer of the + * current log in the same transaction's start undo record pointer in the + * previous log. + * + * xact_urp - undo record pointer to be updated + * urecptr - current transaction's undo record pointer which need to be set in + * the previous transaction's header. + */ +static void +UndoRecordPrepareUpdateNext(UndoRecordInsertContext *context, + UndoRecPtr urecptr, UndoRecPtr xact_urp) +{ + UndoLogSlot *slot; + int index = 0; + int offset; + + /* + * The absence of previous transaction's undo indicate that this backend + * is preparing its first undo in which case we have nothing to update. + */ + if (!UndoRecPtrIsValid(xact_urp)) + return; + + slot = UndoLogGetSlot(UndoRecPtrGetLogNo(xact_urp), false); + + /* + * Acquire the discard lock before reading the undo record so that discard + * worker doesn't remove the record while we are in process of reading it. + */ + LWLockAcquire(&slot->discard_update_lock, LW_SHARED); + /* Check if it is already discarded. */ + if (UndoRecPtrIsDiscarded(xact_urp)) + { + /* Release lock and return. */ + LWLockRelease(&slot->discard_update_lock); + return; + } + + /* Compute the offset of the uur_next in the undo record. */ + offset = SizeOfUndoRecordHeader + + offsetof(UndoRecordTransaction, urec_next); + + index = UndoRecordPrepareTransInfo(context, xact_urp, + sizeof(UndoRecPtr), offset); + + /* + * Set the next pointer in xact_urec_info, this will be overwritten in + * actual undo record during update phase. + */ + context->xact_urec_info[index].next = urecptr; + + /* We can now release the discard lock as we have read the undo record. */ + LWLockRelease(&slot->discard_update_lock); +} + +/* + * Overwrite the first undo record of the previous transaction to update its + * next pointer. + * + * This will insert the already prepared record by UndoRecordPrepareTransInfo. + * This must be called under the critical section. This will just overwrite the + * header of the undo record. + */ +static void +UndoRecordUpdateTransInfo(UndoRecordInsertContext *context, int idx) +{ + Page page = NULL; + int i = 0; + int write_bytes; + int write_offset; + char *sourceptr; + XactUndoRecordInfo *xact_info = &context->xact_urec_info[idx]; + + /* Whether to update the next or undo apply progress. */ + if (UndoRecPtrIsValid(xact_info->next)) + { + sourceptr = (char *) &xact_info->next; + write_bytes = sizeof(xact_info->next); + } + else + { + sourceptr = (char *) &xact_info->progress; + write_bytes = sizeof(xact_info->progress); + } + + /* Where to start writing in the current block. */ + write_offset = xact_info->offset; + + /* + * Start writing directly from the write offset calculated during prepare + * phase. And, loop until we write required bytes. + */ + while (write_bytes > 0) + { + Buffer buffer; + int buf_idx; + int can_write; + char *writeptr; + + buf_idx = xact_info->idx_undo_buffers[i]; + buffer = context->prepared_undo_buffers[buf_idx].buf; + + /* How may bytes can be written in the current page. */ + can_write = Min((BLCKSZ - write_offset), write_bytes); + + /* + * If buffer is valid then write it otherwise just skip writing it but + * compute the variable for writing into the next block. + */ + if (BufferIsValid(buffer)) + { + page = BufferGetPage(buffer); + + /* Compute the write pointer. */ + writeptr = (char *) page + write_offset; + + /* Copy the bytes we can write. */ + memcpy(writeptr, sourceptr, can_write); + MarkBufferDirty(buffer); + } + + /* Update bookkeeping information. */ + write_bytes -= can_write; + sourceptr += can_write; + write_offset = UndoLogBlockHeaderSize; + i++; + } +} + +/* + * Find the block number in undo buffer array + * + * If it is present then just return its index otherwise search the buffer and + * insert an entry and lock the buffer in exclusive mode. + * + * Undo log insertions are append-only. If the caller is writing new data + * that begins exactly at the beginning of a page, then there cannot be any + * useful data after that point. In that case RBM_ZERO can be passed in as + * rbm so that we can skip a useless read of a disk block. In all other + * cases, RBM_NORMAL should be passed in, to read the page in if it doesn't + * happen to be already in the buffer pool. + */ +static int +UndoGetBufferSlot(UndoRecordInsertContext *context, + RelFileNode rnode, + BlockNumber blk, + ReadBufferMode rbm) +{ + int i; + Buffer buffer; + XLogRedoAction action = BLK_NEEDS_REDO; + PreparedUndoBuffer *prepared_buffer; + UndoLogCategory category = context->alloc_context.category; + + /* Don't do anything, if we already have a buffer pinned for the block. */ + for (i = 0; i < context->nprepared_undo_buffer; i++) + { + prepared_buffer = &context->prepared_undo_buffers[i]; + + /* + * It's not enough to just compare the block number because the + * undo_buffer might holds the undo from different undo logs (e.g when + * previous transaction start header is in previous undo log) so + * compare (logno + blkno). + */ + if ((blk == prepared_buffer->blk) && + (prepared_buffer->logno == rnode.relNode)) + { + /* caller must hold exclusive lock on buffer */ + Assert(BufferIsLocal(prepared_buffer->buf) || + LWLockHeldByMeInMode(BufferDescriptorGetContentLock( + GetBufferDescriptor(prepared_buffer->buf - 1)), + LW_EXCLUSIVE)); + return i; + } + } + + /* + * We did not find the block so allocate the buffer and insert into the + * undo buffer array. + */ + if (InRecovery) + action = XLogReadBufferForRedoBlock(context->alloc_context.xlog_record, + rnode, + UndoLogForkNum, + blk, + rbm, + false, + &buffer); + else + { + buffer = ReadBufferWithoutRelcache(rnode, + UndoLogForkNum, + blk, + rbm, + NULL, + RelPersistenceForUndoLogCategory(category)); + + /* Lock the buffer */ + LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE); + } + + prepared_buffer = + &context->prepared_undo_buffers[context->nprepared_undo_buffer]; + + if (action == BLK_NOTFOUND) + { + Assert(InRecovery); + + prepared_buffer->buf = InvalidBuffer; + prepared_buffer->blk = InvalidBlockNumber; + } + else + { + prepared_buffer->buf = buffer; + prepared_buffer->blk = blk; + prepared_buffer->logno = rnode.relNode; + prepared_buffer->zero = rbm == RBM_ZERO; + } + + context->nprepared_undo_buffer++; + + return i; +} + +/* + * Exclude the common info in undo record flag and also set the compression + * info in the context. + * + * This function will check what information we need to include in the current + * undo record based on the undo compression information. And, it will also + * update the compression info if we are writing the first undo record on the + * page. + */ +static bool +UndoSetCommonInfo(UndoCompressionInfo *compressioninfo, + UnpackedUndoRecord *urec, UndoRecPtr urp, + Buffer buffer) +{ + bool record_updated = false; + bool first_complete_undo = false; + UndoRecPtr lasturp = compressioninfo->last_urecptr; + + /* + * If we have valid compression info and the for the same transaction and + * the current undo record is on the same block as the last undo record + * then exclude the common information which are same as first complete + * record on the page. + */ + if (compressioninfo->valid && + FullTransactionIdEquals(compressioninfo->fxid, urec->uur_fxid) && + UndoRecPtrGetBlockNum(urp) == UndoRecPtrGetBlockNum(lasturp)) + { + urec->uur_info &= ~UREC_INFO_XID; + + /* Don't include rmid if it's same. */ + if (urec->uur_rmid == compressioninfo->rmid) + urec->uur_info &= ~UREC_INFO_RMID; + + /* Don't include reloid if it's same. */ + if (urec->uur_reloid == compressioninfo->reloid) + urec->uur_info &= ~UREC_INFO_RELOID; + + /* Don't include cid if it's same. */ + if (urec->uur_cid == compressioninfo->cid) + urec->uur_info &= ~UREC_INFO_CID; + + record_updated = true; + } + + /* + * If the undo record is starting just after the undo page header then + * this is the first complete undo on the page. + */ + if (UndoRecPtrGetPageOffset(urp) == SizeOfUndoPageHeaderData) + first_complete_undo = true; + else if (UndoRecPtrIsValid(lasturp)) + { + /* + * If we already have the valid last undo record pointer which + * inserted undo in this log then we can identify whether this is the + * first undo of the page by checking the block number of the previous + * record and the current record. + */ + if (UndoRecPtrGetBlockNum(urp) != UndoRecPtrGetBlockNum(lasturp)) + first_complete_undo = true; + } + else + { + Page page = BufferGetPage(buffer); + uint16 offset; + UndoPageHeader phdr = (UndoPageHeader) page; + + /* + * We need to compute the offset of the first complete record of the + * page and if this undo record starting from that page then this is + * the first complete record on the page. + */ + offset = SizeOfUndoPageHeaderData + UndoPagePartialRecSize(phdr); + if (UndoRecPtrGetPageOffset(urp) == offset) + first_complete_undo = true; + } + + /* + * If we are writing first undo record for the page the we can set the + * compression so that subsequent records from the same transaction can + * avoid including common information in the undo records. + */ + if (first_complete_undo) + { + /* Set this information. */ + compressioninfo->rmid = urec->uur_rmid; + compressioninfo->reloid = urec->uur_reloid; + compressioninfo->fxid = urec->uur_fxid; + compressioninfo->cid = urec->uur_cid; + + /* Set that we have valid compression info. */ + compressioninfo->valid = true; + } + + return record_updated; +} + +/* + * This function must be called before all the undo records which are going to + * get inserted under a single WAL record. + * + * nprepared - This defines the max number of undo records that can be + * prepared before inserting them. + */ +void +BeginUndoRecordInsert(UndoRecordInsertContext *context, + UndoLogCategory category, + int nprepared, + XLogReaderState *xlog_record) +{ + uint32 nbuffers; + + /* At least one prepared record should be there. */ + if (nprepared <= 0) + elog(ERROR, "at least one undo record should be prepared"); + + /* Initialize undo log context. */ + UndoLogBeginInsert(&context->alloc_context, category, xlog_record); + + /* Initialize undo insert context. */ + context->max_prepared_undo = nprepared; + context->nprepared_undo = 0; + context->nprepared_undo_buffer = 0; + context->nxact_urec_info = 0; + + /* Allocate memory for prepared undo record space. */ + context->prepared_undo = (PreparedUndoSpace *) palloc(nprepared * + sizeof(PreparedUndoSpace)); + + /* Compute number of buffers. */ + nbuffers = (nprepared + MAX_XACT_UNDO_INFO) * MAX_BUFFER_PER_UNDO; + + /* + * Copy the compression global compression info to our context before + * starting prepare because this value might get updated multiple time in + * case of multi-prepare but the global value should be updated only after + * we have successfully inserted the undo record. + */ + memcpy(&context->undo_compression_info[category], + &undo_compression_info[category], sizeof(UndoCompressionInfo)); + + /* Allocate memory for the prepared buffers. */ + context->prepared_undo_buffers = + palloc(nbuffers * sizeof(PreparedUndoBuffer)); +} + +/* + * Call PrepareUndoInsert to tell the undo subsystem about the undo record you + * intended to insert. Upon return, the necessary undo buffers are pinned and + * locked. + * + * This should be done before any critical section is established, since it + * can fail. + */ +UndoRecPtr +PrepareUndoInsert(UndoRecordInsertContext *context, + UnpackedUndoRecord *urec, + Oid dbid) +{ + UndoRecordSize size; + UndoRecPtr urecptr = InvalidUndoRecPtr; + RelFileNode rnode; + UndoRecordSize cur_size = 0; + BlockNumber cur_blk; + FullTransactionId fxid; + int starting_byte; + int index = 0; + int bufidx; + bool logswitched = false; + bool resize = false; + ReadBufferMode rbm; + bool need_xact_header; + UndoRecPtr last_xact_start; + UndoRecPtr prevlog_xact_start = InvalidUndoRecPtr; + UndoRecPtr prevlog_insert_urp = InvalidUndoRecPtr; + UndoRecPtr prevlogurp = InvalidUndoRecPtr; + PreparedUndoSpace *prepared_undo; + UndoCompressionInfo *compression_info = + &context->undo_compression_info[context->alloc_context.category]; + + /* Already reached maximum prepared limit. */ + if (context->nprepared_undo == context->max_prepared_undo) + elog(ERROR, "already reached the maximum prepared limit"); + + /* Extract the full transaction id from the input undo record. */ + fxid = urec->uur_fxid; + Assert(FullTransactionIdIsValid(fxid)); + + /* + * We don't yet know if this record needs a transaction header (ie is the + * first undo record for a given transaction in a given undo log), because + * you can only find out by allocating. We'll resolve this circularity by + * allocating enough space for a transaction header. Similarly log switch + * will only be detected after allocation so include the log switch header + * and common information because in case of log switch we need to include + * log switch header and also we need to include common header. After + * allocation We'll only advance by as many bytes as we turn out to need. + */ + UndoRecordSetInfo(urec); + urec->uur_info |= UREC_INFO_TRANSACTION; + urec->uur_info |= UREC_INFO_LOGSWITCH; + urec->uur_info |= UREC_INFO_PAGE_COMMON; + + size = UndoRecordExpectedSize(urec); + + /* Allocate space for the record. */ + if (InRecovery) + { + /* + * We'll figure out where the space needs to be allocated by + * inspecting the xlog_record. We don't expect to see temporary or + * unlogged undo data here. + */ + Assert(context->alloc_context.category != UNDO_TEMP && + context->alloc_context.category != UNDO_UNLOGGED); + urecptr = UndoLogAllocateInRecovery(&context->alloc_context, + XidFromFullTransactionId(fxid), + size, + &need_xact_header, + &last_xact_start, + &prevlog_xact_start, + &prevlogurp); + } + else + { + /* Allocate space for writing the undo record. */ + urecptr = UndoLogAllocate(&context->alloc_context, + size, + &need_xact_header, &last_xact_start, + &prevlog_xact_start, &prevlog_insert_urp); + + /* + * If prevlog_xact_start is a valid undo record pointer that means + * this transaction's undo records are split across undo logs. + */ + if (UndoRecPtrIsValid(prevlog_xact_start)) + { + uint16 prevlen; + + /* + * If undo log is switch during transaction then we must get a + * valid insert location in the previous undo log so that we can + * compute the undo record pointer of the transaction's last + * record in the previous undo log. + */ + Assert(UndoRecPtrIsValid(prevlog_insert_urp)); + + /* Fetch length of the last undo record of the previous log. */ + prevlen = UndoGetPrevRecordLen(prevlog_insert_urp, InvalidBuffer, + context->alloc_context.category); + + /* + * If the undo log got switched during the transaction then for + * collecting all the undo record for the transaction during bulk + * fetch, we can not read the prevlen from the end of the record + * as we will not know what was the previous undo log. So during + * log switch we will directly store the last undo record pointer + * of the transaction into transaction's first record of the next + * undo log. + * + * TODO: instead of storing this in the transaction header we can + * have separate undo log switch header and store it there. + */ + prevlogurp = + MakeUndoRecPtr(UndoRecPtrGetLogNo(prevlog_insert_urp), + (UndoRecPtrGetOffset(prevlog_insert_urp) - prevlen)); + + /* + * Undo log switched so set prevlog info in current undo log. + * + * XXX can we do this directly in UndoLogAllocate ? but for that + * the UndoLogAllocate might need to read the length of the last + * undo record from the previous undo log but for that it might + * use callback? + */ + UndoLogSwitchSetPrevLogInfo(UndoRecPtrGetLogNo(urecptr), + prevlog_xact_start, prevlogurp); + } + } + + /* + * If undo log is switched then set the logswitch flag and also reset the + * compression info because we can use same compression info for the new + * undo log. + */ + if (UndoRecPtrIsValid(prevlog_xact_start)) + { + logswitched = true; + compression_info->valid = false; + compression_info->last_urecptr = InvalidUndoRecPtr; + } + + /* + * If we need a transaction header then allocate memory for it and + * initialize it. + */ + if (need_xact_header) + { + urec->uur_txn = palloc(SizeOfUndoRecordTransaction); + urec->uur_txn->urec_dbid = dbid; + urec->uur_txn->urec_progress = InvalidBlockNumber; + urec->uur_txn->urec_next = InvalidUndoRecPtr; + } + else + { + /* We don't need a transaction header after all. */ + urec->uur_info &= ~UREC_INFO_TRANSACTION; + resize = true; + urec->uur_txn = NULL; + } + + /* + * If undo log got switched then initialize the log switch header + * otherwise reset it in uur_info and recalculate the size. + */ + if (logswitched) + { + urec->uur_logswitch = palloc(SizeOfUndoRecordLogSwitch); + urec->uur_logswitch->urec_prevurp = prevlogurp; + urec->uur_logswitch->urec_prevlogstart = prevlog_xact_start; + } + else + { + /* We don't need a log transaction header after all. */ + urec->uur_info &= ~UREC_INFO_LOGSWITCH; + resize = true; + urec->uur_logswitch = NULL; + } + + /* + * If there is a physically preceding transaction in this undo log, and we + * are writing the first record for this transaction that is in this undo + * log (not necessarily the first ever for the transaction, because we + * could have switched logs), then we need to update the size of the + * preceding transaction. + */ + if (need_xact_header && + UndoRecPtrGetOffset(urecptr) > UndoLogBlockHeaderSize) + UndoRecordPrepareUpdateNext(context, urecptr, last_xact_start); + + cur_blk = UndoRecPtrGetBlockNum(urecptr); + UndoRecPtrAssignRelFileNode(rnode, urecptr); + starting_byte = UndoRecPtrGetPageOffset(urecptr); + + /* + * If we happen to be writing the very first byte into this page, then + * there is no need to read from disk. + */ + if (starting_byte == UndoLogBlockHeaderSize) + rbm = RBM_ZERO; + else + rbm = RBM_NORMAL; + + prepared_undo = &context->prepared_undo[context->nprepared_undo]; + + do + { + bufidx = UndoGetBufferSlot(context, rnode, cur_blk, rbm); + if (cur_size == 0) + cur_size = BLCKSZ - starting_byte; + else + cur_size += BLCKSZ - UndoLogBlockHeaderSize; + + /* undo record can't use buffers more than MAX_BUFFER_PER_UNDO. */ + Assert(index < MAX_BUFFER_PER_UNDO); + + /* Keep the track of the buffers we have pinned and locked. */ + prepared_undo->undo_buffer_idx[index++] = bufidx; + + /* + * If we need more pages they'll be all new so we can definitely skip + * reading from disk. + */ + rbm = RBM_ZERO; + cur_blk++; + } while (cur_size < size); + + /* + * Set/overwrite compression info if required and also exclude the common + * fields from the undo record if possible. + */ + if (UndoSetCommonInfo(compression_info, urec, urecptr, + context->prepared_undo_buffers[prepared_undo->undo_buffer_idx[0]].buf)) + resize = true; + + if (resize) + size = UndoRecordExpectedSize(urec); + + /* + * If the transaction's undo records are split across the undo logs. So + * we need to update our own transaction header in the previous log. + */ + if (logswitched) + { + Assert(UndoRecPtrIsValid(prevlogurp)); + UndoRecordPrepareUpdateNext(context, urecptr, prevlog_xact_start); + } + + UndoLogAdvance(&context->alloc_context, size); + + /* + * Save prepared undo record information into the context which will be + * used by InsertPreparedUndo to insert the undo record. + */ + prepared_undo->urec = urec; + prepared_undo->urp = urecptr; + prepared_undo->size = size; + + /* Set the current undo pointer in the compression info. */ + compression_info->last_urecptr = urecptr; + + context->nprepared_undo++; + + return urecptr; +} + +/* + * Insert a previously-prepared undo records. + * + * This function will write the actual undo record into the buffers which are + * already pinned and locked in PreparedUndoInsert, and mark them dirty. This + * step should be performed inside a critical section. + */ +void +InsertPreparedUndo(UndoRecordInsertContext *context) +{ + UndoPackContext ucontext = {{0}}; + PreparedUndoSpace *prepared_undo; + Page page = NULL; + int starting_byte; + int bufidx = 0; + int idx; + int i; + + /* There must be at least one prepared undo record. */ + Assert(context->nprepared_undo > 0); + + /* + * This must be called under a critical section or we must be in recovery. + */ + Assert(InRecovery || CritSectionCount > 0); + + for (idx = 0; idx < context->nprepared_undo; idx++) + { + prepared_undo = &context->prepared_undo[idx]; + + Assert(prepared_undo->size == + UndoRecordExpectedSize(prepared_undo->urec)); + + bufidx = 0; + + /* + * Compute starting offset of the page where to start inserting undo + * record. + */ + starting_byte = UndoRecPtrGetPageOffset(prepared_undo->urp); + + /* Initiate inserting the undo record. */ + BeginInsertUndo(&ucontext, prepared_undo->urec); + + /* Main loop for writing the undo record. */ + do + { + Buffer buffer; + + buffer = context->prepared_undo_buffers[ + prepared_undo->undo_buffer_idx[bufidx]].buf; + + /* + * During recovery, there might be some blocks which are already + * deleted due to some discard command so we can just skip + * inserting into those blocks. + */ + if (!BufferIsValid(buffer)) + { + Assert(InRecovery); + + /* + * Skip actual writing just update the context so that we have + * write offset for inserting into next blocks. + */ + SkipInsertingUndoData(&ucontext, BLCKSZ - starting_byte); + if (ucontext.stage == UNDO_PACK_STAGE_DONE) + break; + } + else + { + page = BufferGetPage(buffer); + + /* + * Initialize the page whenever we try to write the first + * record in page. We start writing immediately after the + * block header. + */ + if (starting_byte == UndoLogBlockHeaderSize) + UndoPageInit(page, BLCKSZ, prepared_undo->urec->uur_info, + ucontext.already_processed, + prepared_undo->urec->uur_tuple.len, + prepared_undo->urec->uur_payload.len); + + /* + * Try to insert the record into the current page. If it + * doesn't succeed then recall the routine with the next page. + */ + InsertUndoData(&ucontext, page, starting_byte); + if (ucontext.stage == UNDO_PACK_STAGE_DONE) + { + MarkBufferDirty(buffer); + break; + } + MarkBufferDirty(buffer); + } + + /* Insert remaining record in next block. */ + starting_byte = UndoLogBlockHeaderSize; + bufidx++; + + /* undo record can't use buffers more than MAX_BUFFER_PER_UNDO. */ + Assert(bufidx < MAX_BUFFER_PER_UNDO); + } while (true); + + /* Advance the insert pointer past this record. */ + UndoLogAdvanceFinal(prepared_undo->urp, prepared_undo->size); + } + + /* Update previously prepared transaction headers. */ + for (i = 0; i < context->nxact_urec_info; i++) + UndoRecordUpdateTransInfo(context, i); + + /* + * We have successfully inserted prepared undo records so overwrite the + * global compression. + */ + memcpy(&undo_compression_info[context->alloc_context.category], + &context->undo_compression_info[context->alloc_context.category], + sizeof(UndoCompressionInfo)); + +} + +/* + * Release all the memory and buffer pins hold for inserting the undo records. + */ +void +FinishUndoRecordInsert(UndoRecordInsertContext *context) +{ + int i; + + /* Release buffer pins and lock. */ + for (i = 0; i < context->nprepared_undo_buffer; i++) + { + if (BufferIsValid(context->prepared_undo_buffers[i].buf)) + UnlockReleaseBuffer(context->prepared_undo_buffers[i].buf); + } + + /* + * Release memory for the transaction header and log switch header if we + * have allocated it in the prepare time. + */ + for (i = 0; i < context->nprepared_undo; i++) + { + if (context->prepared_undo[i].urec->uur_txn) + pfree(context->prepared_undo[i].urec->uur_txn); + if (context->prepared_undo[i].urec->uur_logswitch) + pfree(context->prepared_undo[i].urec->uur_logswitch); + } + + /* Free memory allocated for the prepare undo and prepared buffers. */ + pfree(context->prepared_undo_buffers); + pfree(context->prepared_undo); +} + +/* + * Helper function for UndoGetOneRecord + * + * If any of rmid/reloid/xid/cid is not available in the undo record, then + * it will get the information from the first complete undo record in the + * page. + */ +static void +GetCommonUndoRecInfo(UndoPackContext *ucontext, UndoRecPtr urp, + RelFileNode rnode, UndoLogCategory category, Buffer buffer) +{ + /* + * If any of the common header field is not available in the current undo + * record then we must read it from the first complete record of the page. + */ + if ((ucontext->urec_hd.urec_info & UREC_INFO_PAGE_COMMON) != + UREC_INFO_PAGE_COMMON) + { + UnpackedUndoRecord first_uur = {0}; + Page page = BufferGetPage(buffer); + UndoPageHeader undo_phdr = (UndoPageHeader) page; + UndoRecPtr first_urp = InvalidUndoRecPtr; + Size partial_rec_size = SizeOfUndoPageHeaderData; + BlockNumber blkno = UndoRecPtrGetBlockNum(urp); + + /* + * If there is a partial record in the page then compute the size of + * it so that we can compute the undo record pointer of the first + * complete undo record of the page. + */ + if (undo_phdr->record_offset != 0) + partial_rec_size += UndoPagePartialRecSize(undo_phdr); + + /* + * Compute the undo record pointer of the first complete record of the + * page. + */ + first_urp = MakeUndoRecPtr(rnode.relNode, + UndoRecPageOffsetGetRecPtr(partial_rec_size, blkno)); + + /* Fetch the first undo record of the page. */ + UndoGetOneRecord(&first_uur, first_urp, rnode, category, &buffer); + + /* + * Get all missing common header information from the first undo + * records. + */ + if ((ucontext->urec_hd.urec_info & UREC_INFO_RMID) == 0) + ucontext->urec_rmid = first_uur.uur_rmid; + + if ((ucontext->urec_hd.urec_info & UREC_INFO_RELOID) == 0) + ucontext->urec_reloid = first_uur.uur_reloid; + + if ((ucontext->urec_hd.urec_info & UREC_INFO_XID) == 0) + ucontext->urec_fxid = first_uur.uur_fxid; + + if ((ucontext->urec_hd.urec_info & UREC_INFO_CID) == 0) + ucontext->urec_cid = first_uur.uur_cid; + + ucontext->urec_hd.urec_info |= UREC_INFO_PAGE_COMMON; + } +} + +/* + * Helper function for UndoFetchRecord and UndoBulkFetchRecord + * + * curbuf - If an input buffer is valid then this function will not release the + * pin on that buffer. If the buffer is not valid then it will assign curbuf + * with the first buffer of the current undo record and also it will keep the + * pin and lock on that buffer in a hope that while traversing the undo chain + * the caller might want to read the previous undo record from the same block. + */ +static UnpackedUndoRecord * +UndoGetOneRecord(UnpackedUndoRecord *urec, UndoRecPtr urp, RelFileNode rnode, + UndoLogCategory category, Buffer *curbuf) +{ + Page page; + int starting_byte = UndoRecPtrGetPageOffset(urp); + BlockNumber cur_blk; + UndoPackContext ucontext = {{0}}; + Buffer buffer = *curbuf; + + cur_blk = UndoRecPtrGetBlockNum(urp); + + /* Initiate unpacking one undo record. */ + BeginUnpackUndo(&ucontext); + + while (true) + { + /* If we already have a buffer then no need to allocate a new one. */ + if (!BufferIsValid(buffer)) + { + buffer = ReadBufferWithoutRelcache(rnode, UndoLogForkNum, cur_blk, + RBM_NORMAL, NULL, + RelPersistenceForUndoLogCategory(category)); + + /* + * Remember the first buffer where this undo started as next undo + * record what we fetch might fall on the same buffer. + */ + if (!BufferIsValid(*curbuf)) + *curbuf = buffer; + } + + /* Acquire shared lock on the buffer before reading undo from it. */ + LockBuffer(buffer, BUFFER_LOCK_SHARE); + + page = BufferGetPage(buffer); + + UnpackUndoData(&ucontext, page, starting_byte); + + /* + * We are done if we have reached to the done stage otherwise move to + * next block and continue reading from there. + */ + if (ucontext.stage == UNDO_PACK_STAGE_DONE) + { + if (buffer != *curbuf) + UnlockReleaseBuffer(buffer); + + /* + * Get any of the missing fields from the first record of the + * page. + */ + GetCommonUndoRecInfo(&ucontext, urp, rnode, category, *curbuf); + break; + } + + /* + * The record spans more than a page so we would have copied it (see + * UnpackUndoRecord). In such cases, we can release the buffer. + */ + if (buffer != *curbuf) + UnlockReleaseBuffer(buffer); + buffer = InvalidBuffer; + + /* Go to next block. */ + cur_blk++; + starting_byte = UndoLogBlockHeaderSize; + } + + /* Final step of unpacking. */ + FinishUnpackUndo(&ucontext, urec); + + /* Unlock the buffer but keep the pin. */ + LockBuffer(*curbuf, BUFFER_LOCK_UNLOCK); + + return urec; +} + +/* + * BeginUndoFetch to fetch undo record. + */ +void +BeginUndoFetch(UndoRecordFetchContext *context) +{ + context->buffer = InvalidBuffer; + context->urp = InvalidUndoRecPtr; +} + +/* + * Fetch the undo record for given undo record pointer. + * + * This will internally allocate the memory for the unpacked undo record which + * intern will hold the pointers to the optional headers and the variable data. + * The undo record should be freed by the caller by calling ReleaseUndoRecord. + * This function will old the pin on the buffer where we read the previous undo + * record so that when this function is called repeatedly with the same context + * then it can be benefitted by avoid reading the buffer again if the current + * undo record is in the same buffer. + */ +UnpackedUndoRecord * +UndoFetchRecord(UndoRecordFetchContext *context, UndoRecPtr urp) +{ + RelFileNode rnode; + int logno; + UndoLogSlot *slot; + UnpackedUndoRecord *uur = NULL; + + logno = UndoRecPtrGetLogNo(urp); + slot = UndoLogGetSlot(logno, true); + + /* + * If slot is NULL that means undo log number is unknown. Presumably it + * has been entirely discarded. + */ + if (slot == NULL) + return NULL; + + /* + * Prevent UndoDiscardOneLog() from discarding data while we try to read + * it. Usually we would acquire log->mutex to read log->meta members, but + * in this case we know that discard can't move without also holding + * log->discard_lock. + * + * In Hot Standby mode log->oldest_data is never initialized because it's + * get updated by undo discard worker whereas in HotStandby undo logs are + * getting discarded using discard WAL. So in HotStandby we can directly + * check whether the undo record pointer is discarded or not. But, we can + * not do same for normal case because discard worker can concurrently + * discard the undo logs. + * + * XXX We can avoid this check by always initializing log->oldest_data in + * HotStandby mode as well whenever we apply discard WAL. But, for doing + * that we need to acquire discard lock just for setting this variable? + */ + if (InHotStandby) + { + if (UndoRecPtrIsDiscarded(urp)) + return NULL; + } + else + { + LWLockAcquire(&slot->discard_lock, LW_SHARED); + if (slot->logno != logno || urp < slot->oldest_data) + { + /* + * The slot has been recycled because the undo log was entirely + * discarded, or the pointer is before the oldest data. + */ + LWLockRelease(&slot->discard_lock); + return NULL; + } + } + + /* + * Allocate memory for holding the undo record, caller should be + * responsible for freeing this memory by calling UndoRecordRelease. + */ + uur = palloc0(sizeof(UnpackedUndoRecord)); + UndoRecPtrAssignRelFileNode(rnode, urp); + + /* + * Before fetching the next record check whether we have a valid buffer in + * the context. If so and if we are reading the current record from the + * same then pass that buffer to fetch the undo record, otherwise release + * the buffer. + */ + if (BufferIsValid(context->buffer) && + (UndoRecPtrGetLogNo(context->urp) != UndoRecPtrGetLogNo(urp) || + UndoRecPtrGetBlockNum(context->urp) != UndoRecPtrGetBlockNum(urp))) + { + ReleaseBuffer(context->buffer); + context->buffer = InvalidBuffer; + } + + /* Fetch the current undo record. */ + UndoGetOneRecord(uur, urp, rnode, slot->meta.category, &context->buffer); + + /* Release the discard lock after fetching the record. */ + if (!InHotStandby) + LWLockRelease(&slot->discard_lock); + + context->urp = urp; + + return uur; +} + +/* + * Finish undo record fetch. + */ +void +FinishUndoFetch(UndoRecordFetchContext *context) +{ + if (BufferIsValid(context->buffer)) + ReleaseBuffer(context->buffer); +} + +/* + * Release the memory of the undo record allocated by UndoFetchRecord and + * UndoBulkFetchRecord. + */ +void +UndoRecordRelease(UnpackedUndoRecord *urec) +{ + /* Release the memory of payload data if we allocated it. */ + if (urec->uur_payload.data) + pfree(urec->uur_payload.data); + + /* Release memory of tuple data if we allocated it. */ + if (urec->uur_tuple.data) + pfree(urec->uur_tuple.data); + + /* Release memory of the transaction header if we allocated it. */ + if (urec->uur_txn) + pfree(urec->uur_txn); + + /* Release memory of the logswitch header if we allocated it. */ + if (urec->uur_logswitch) + pfree(urec->uur_logswitch); + + /* Release the memory of the undo record. */ + pfree(urec); +} + +/* + * Prefetch undo pages, if prefetch_pages are behind prefetch_target + */ +static void +PrefetchUndoPages(RelFileNode rnode, int prefetch_target, int *prefetch_pages, + BlockNumber to_blkno, BlockNumber from_blkno, + UndoLogCategory category) +{ + int nprefetch; + BlockNumber startblock; + BlockNumber lastprefetched; + + /* Calculate last prefetched page in the previous iteration. */ + lastprefetched = from_blkno - *prefetch_pages; + + /* We have already prefetched all the pages of the transaction's undo. */ + if (lastprefetched <= to_blkno) + return; + + /* Calculate number of blocks to be prefetched. */ + nprefetch = + Min(prefetch_target - *prefetch_pages, lastprefetched - to_blkno); + + /* Where to start prefetch. */ + startblock = lastprefetched - nprefetch; + + while (nprefetch--) + { + PrefetchBufferWithoutRelcache(rnode, MAIN_FORKNUM, startblock++, + category == UNDO_TEMP); + (*prefetch_pages)++; + } +} + +/* + * Read undo records of the transaction in bulk + * + * Read undo records between from_urecptr and to_urecptr until we exhaust the + * the memory size specified by undo_apply_size. If we could not read all the + * records till to_urecptr then the caller should consume current set of records + * and call this function again. + * + * from_urecptr - Where to start fetching the undo records. If we can not + * read all the records because of memory limit then this + * will be set to the previous undo record pointer from where + * we need to start fetching on next call. Otherwise it will + * be set to InvalidUndoRecPtr. + * to_urecptr - Last undo record pointer to be fetched. + * undo_apply_size - Memory segment limit to collect undo records. + * nrecords - Number of undo records read. + * one_page - Caller is applying undo only for one block not for + * complete transaction. If this is set true then instead + * of following transaction undo chain using prevlen we will + * follow the block prev chain of the block so that we can + * avoid reading many unnecessary undo records of the + * transaction. + */ +UndoRecInfo * +UndoBulkFetchRecord(UndoRecPtr *from_urecptr, UndoRecPtr to_urecptr, + int undo_apply_size, int *nrecords, bool one_page) +{ + RelFileNode rnode; + UndoRecPtr urecptr, + prev_urec_ptr; + BlockNumber blkno; + BlockNumber to_blkno; + Buffer buffer = InvalidBuffer; + UnpackedUndoRecord *uur = NULL; + UndoRecInfo *urp_array; + int urp_array_size = 1024; + int urp_index = 0; + int prefetch_target = 0; + int prefetch_pages = 0; + Size total_size = 0; + FullTransactionId fxid = InvalidFullTransactionId; + + /* + * In one_page mode we are fetching undo only for one page instead of + * fetching all the undo of the transaction. Basically, we are fetching + * interleaved undo records. So it does not make sense to do any prefetch + * in that case. Also, if we are fetching undo records from more than one + * log, we don't know the boundaries for prefetching. Hence, we can't use + * prefetching in this case. + */ + if (!one_page && + (UndoRecPtrGetLogNo(*from_urecptr) == UndoRecPtrGetLogNo(to_urecptr))) + prefetch_target = target_prefetch_pages; + + /* + * Allocate initial memory to hold the undo record info, we can expand it + * if needed. + */ + urp_array = (UndoRecInfo *) palloc(sizeof(UndoRecInfo) * urp_array_size); + urecptr = *from_urecptr; + + prev_urec_ptr = InvalidUndoRecPtr; + *from_urecptr = InvalidUndoRecPtr; + + /* Read undo chain backward until we reach to the first undo record. */ + while (1) + { + BlockNumber from_blkno; + UndoLogSlot *slot; + UndoLogCategory category; + int size; + int logno; + + logno = UndoRecPtrGetLogNo(urecptr); + slot = UndoLogGetSlot(logno, true); + if (slot == NULL) + { + if (BufferIsValid(buffer)) + ReleaseBuffer(buffer); + return NULL; + } + category = slot->meta.category; + + UndoRecPtrAssignRelFileNode(rnode, urecptr); + to_blkno = UndoRecPtrGetBlockNum(to_urecptr); + from_blkno = UndoRecPtrGetBlockNum(urecptr); + + /* Allocate memory for next undo record. */ + uur = palloc0(sizeof(UnpackedUndoRecord)); + + /* + * If next undo record pointer to be fetched is not on the same block + * then release the old buffer and reduce the prefetch_pages count by + * one as we have consumed one page. Otherwise, just set the old + * buffer into the new undo record so that UndoGetOneRecord don't read + * the buffer again. + */ + blkno = UndoRecPtrGetBlockNum(urecptr); + if (!UndoRecPtrIsValid(prev_urec_ptr) || + UndoRecPtrGetLogNo(prev_urec_ptr) != logno || + UndoRecPtrGetBlockNum(prev_urec_ptr) != blkno) + { + /* Release the previous buffer */ + if (BufferIsValid(buffer)) + { + ReleaseBuffer(buffer); + buffer = InvalidBuffer; + } + + if (prefetch_pages > 0) + prefetch_pages--; + } + + /* + * If prefetch_pages are half of the prefetch_target then it's time to + * prefetch again. + */ + if (prefetch_pages < prefetch_target / 2) + PrefetchUndoPages(rnode, prefetch_target, &prefetch_pages, to_blkno, + from_blkno, category); + + /* + * In one_page mode it's possible that the undo of the transaction + * might have been applied by worker and undo got discarded. Prevent + * discard worker from discarding undo data while we are reading it. + * See detail comment in UndoFetchRecord. In normal mode we are + * holding transaction undo action lock so it can not be discarded. + */ + if (one_page) + { + /* Refer comments in UndoFetchRecord. */ + if (InHotStandby) + { + if (UndoRecPtrIsDiscarded(urecptr)) + break; + } + else + { + LWLockAcquire(&slot->discard_lock, LW_SHARED); + if (slot->logno != logno || urecptr < slot->oldest_data) + { + /* + * The undo log slot has been recycled because it was + * entirely discarded, or the data has been discarded + * already. + */ + LWLockRelease(&slot->discard_lock); + break; + } + } + + /* Read the undo record. */ + UndoGetOneRecord(uur, urecptr, rnode, category, &buffer); + + /* Release the discard lock after fetching the record. */ + if (!InHotStandby) + LWLockRelease(&slot->discard_lock); + } + else + UndoGetOneRecord(uur, urecptr, rnode, category, &buffer); + + /* + * As soon as the transaction id is changed we can stop fetching the + * undo record. Ideally, to_urecptr should control this but while + * reading undo only for a page we don't know what is the end undo + * record pointer for the transaction. + */ + if (one_page) + { + if (!FullTransactionIdIsValid(fxid)) + fxid = uur->uur_fxid; + else if (!FullTransactionIdEquals(fxid, uur->uur_fxid)) + break; + } + + /* Remember the previous undo record pointer. */ + prev_urec_ptr = urecptr; + + /* + * Calculate the previous undo record pointer of the transaction. If + * we are reading undo only for a page then follow the blkprev chain + * of the page. Otherwise, calculate the previous undo record pointer + * using transaction's current undo record pointer and the prevlen. If + * undo record has a valid uur_prevurp, this is the case of log switch + * during the transaction so we can directly use uur_prevurp as our + * previous undo record pointer of the transaction. + */ + if (one_page) + urecptr = uur->uur_prevundo; + else if (uur->uur_logswitch) + urecptr = uur->uur_logswitch->urec_prevurp; + else if (prev_urec_ptr == to_urecptr || + uur->uur_info & UREC_INFO_TRANSACTION) + urecptr = InvalidUndoRecPtr; + else + urecptr = UndoGetPrevUndoRecptr(prev_urec_ptr, buffer, category); + + /* We have consumed all elements of the urp_array so expand its size. */ + if (urp_index >= urp_array_size) + { + urp_array_size *= 2; + urp_array = + repalloc(urp_array, sizeof(UndoRecInfo) * urp_array_size); + } + + /* Add entry in the urp_array */ + urp_array[urp_index].index = urp_index; + urp_array[urp_index].urp = prev_urec_ptr; + urp_array[urp_index].uur = uur; + urp_index++; + + /* We have fetched all the undo records for the transaction. */ + if (!UndoRecPtrIsValid(urecptr) || (prev_urec_ptr == to_urecptr)) + break; + + size = UnpackedUndoRecordSize(uur); + total_size += size; + + /* + * Including current record, if we have crossed the memory limit or + * undo log got switched then stop processing more records. Remember + * to set the from_urecptr so that on next call we can resume fetching + * undo records where we left it. + */ + if (total_size >= undo_apply_size || uur->uur_logswitch) + { + *from_urecptr = urecptr; + break; + } + } + + /* Release the last buffer. */ + if (BufferIsValid(buffer)) + ReleaseBuffer(buffer); + + *nrecords = urp_index; + + return urp_array; +} + +/* + * Register the undo buffers. + */ +void +RegisterUndoLogBuffers(UndoRecordInsertContext *context, uint8 first_block_id) +{ + int idx; + int flags; + + for (idx = 0; idx < context->nprepared_undo_buffer; idx++) + { + flags = context->prepared_undo_buffers[idx].zero + ? REGBUF_KEEP_DATA_AFTER_CP | REGBUF_WILL_INIT + : REGBUF_KEEP_DATA_AFTER_CP; + XLogRegisterBuffer(first_block_id + idx, + context->prepared_undo_buffers[idx].buf, flags); + UndoLogRegister(&context->alloc_context, first_block_id + idx, + context->prepared_undo_buffers[idx].logno); + } +} + +/* + * Set LSN on undo page. +*/ +void +UndoLogBuffersSetLSN(UndoRecordInsertContext *context, XLogRecPtr recptr) +{ + int idx; + + for (idx = 0; idx < context->nprepared_undo_buffer; idx++) + PageSetLSN(BufferGetPage(context->prepared_undo_buffers[idx].buf), + recptr); +} + +/* + * Read length of the previous undo record. + * + * This function will take an undo record pointer as an input and read the + * length of the previous undo record which is stored at the end of the previous + * undo record. If the undo record is split then this will add the undo block + * header size in the total length. + */ +static uint16 +UndoGetPrevRecordLen(UndoRecPtr urp, Buffer input_buffer, + UndoLogCategory category) +{ + UndoLogOffset page_offset = UndoRecPtrGetPageOffset(urp); + BlockNumber cur_blk = UndoRecPtrGetBlockNum(urp); + Buffer buffer = input_buffer; + Page page = NULL; + char *pagedata = NULL; + char prevlen[2]; + RelFileNode rnode; + int byte_to_read = sizeof(uint16); + char persistence; + uint16 prev_rec_len = 0; + + /* Get relfilenode. */ + UndoRecPtrAssignRelFileNode(rnode, urp); + persistence = RelPersistenceForUndoLogCategory(category); + + if (BufferIsValid(buffer)) + { + page = BufferGetPage(buffer); + pagedata = (char *) page; + } + + /* + * Length if the previous undo record is store at the end of that record + * so just fetch last 2 bytes. + */ + while (byte_to_read > 0) + { + /* Read buffer if the current buffer is not valid. */ + if (!BufferIsValid(buffer)) + { + buffer = ReadBufferWithoutRelcache(rnode, UndoLogForkNum, + cur_blk, RBM_NORMAL, NULL, + persistence); + + LockBuffer(buffer, BUFFER_LOCK_SHARE); + + page = BufferGetPage(buffer); + pagedata = (char *) page; + } + + page_offset -= 1; + + /* + * Read current prevlen byte from current block if page_offset hasn't + * reach to undo block header. Otherwise, go to the previous block + * and continue reading from there. + */ + if (page_offset >= UndoLogBlockHeaderSize) + { + prevlen[byte_to_read - 1] = pagedata[page_offset]; + byte_to_read -= 1; + } + else + { + /* + * Release the current buffer if it is not provide by the caller. + */ + if (input_buffer != buffer) + UnlockReleaseBuffer(buffer); + + /* + * Could not read complete prevlen from the current block so go to + * the previous block and start reading from end of the block. + */ + cur_blk -= 1; + page_offset = BLCKSZ; + + /* + * Reset buffer so that we can read it again for the previous + * block. + */ + buffer = InvalidBuffer; + } + } + + prev_rec_len = *(uint16 *) (prevlen); + + /* + * If previous undo record is not completely stored in this page then add + * UndoLogBlockHeaderSize in total length so that the call can use this + * length to compute the undo record pointer of the previous undo record. + */ + if (UndoRecPtrGetPageOffset(urp) - UndoLogBlockHeaderSize < prev_rec_len) + prev_rec_len += UndoLogBlockHeaderSize; + + /* Release the buffer if we have locally read it. */ + if (input_buffer != buffer) + UnlockReleaseBuffer(buffer); + + return prev_rec_len; +} + +/* + * Calculate the previous undo record pointer for the transaction. + * + * This will take current undo record pointer of the transaction as an input + * and calculate the previous undo record pointer of the transaction. + */ +UndoRecPtr +UndoGetPrevUndoRecptr(UndoRecPtr urp, Buffer buffer, + UndoLogCategory category) +{ + UndoLogNumber logno = UndoRecPtrGetLogNo(urp); + UndoLogOffset offset = UndoRecPtrGetOffset(urp); + uint16 prevlen; + + /* Read length of the previous undo record. */ + prevlen = UndoGetPrevRecordLen(urp, buffer, category); + + /* calculate the previous undo record pointer */ + return MakeUndoRecPtr(logno, offset - prevlen); +} diff --git a/src/backend/access/undo/undorecord.c b/src/backend/access/undo/undorecord.c new file mode 100755 index 0000000..a44bfbd --- /dev/null +++ b/src/backend/access/undo/undorecord.c @@ -0,0 +1,1051 @@ +/*------------------------------------------------------------------------- + * + * undorecord.c + * encode and decode undo records + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/backend/access/undo/undorecord.c + *------------------------------------------------------------------------- + */ + +#include "postgres.h" + +#include "access/bufmask.h" +#include "access/subtrans.h" +#include "access/undorecord.h" +#include "catalog/pg_tablespace.h" +#include "storage/block.h" + +/* Prototypes for static functions. */ +static bool InsertUndoBytes(char *sourceptr, int sourcelen, + char **writeptr, char *endptr, + int *total_bytes_written, int *partial_write); +static bool ReadUndoBytes(char *destptr, int readlen, + char **readptr, char *endptr, + int *total_bytes_read, int *partial_read); + + /* + * Compute the header size of the undo record. + */ +Size +UndoRecordHeaderSize(uint16 uur_info) +{ + Size size; + + /* Add fixed header size. */ + size = SizeOfUndoRecordHeader; + + /* Add size of transaction header if it presets. */ + if ((uur_info & UREC_INFO_TRANSACTION) != 0) + size += SizeOfUndoRecordTransaction; + + /* Add size of rmid if it presets. */ + if ((uur_info & UREC_INFO_RMID) != 0) + size += sizeof(RmgrId); + + /* Add size of reloid if it presets. */ + if ((uur_info & UREC_INFO_RELOID) != 0) + size += sizeof(Oid); + + /* Add size of fxid if it presets. */ + if ((uur_info & UREC_INFO_XID) != 0) + size += sizeof(FullTransactionId); + + /* Add size of cid if it presets. */ + if ((uur_info & UREC_INFO_CID) != 0) + size += sizeof(CommandId); + + /* Add size of forknum if it presets. */ + if ((uur_info & UREC_INFO_FORK) != 0) + size += sizeof(ForkNumber); + + /* Add size of prevundo if it presets. */ + if ((uur_info & UREC_INFO_PREVUNDO) != 0) + size += sizeof(UndoRecPtr); + + /* Add size of the block header if it presets. */ + if ((uur_info & UREC_INFO_BLOCK) != 0) + size += SizeOfUndoRecordBlock; + + /* Add size of the log switch header if it presets. */ + if ((uur_info & UREC_INFO_LOGSWITCH) != 0) + size += SizeOfUndoRecordLogSwitch; + + /* Add size of the payload header if it presets. */ + if ((uur_info & UREC_INFO_PAYLOAD) != 0) + size += SizeOfUndoRecordPayload; + + return size; +} + +/* + * Compute and return the expected size of an undo record. + */ +Size +UndoRecordExpectedSize(UnpackedUndoRecord *uur) +{ + Size size; + + /* Header size. */ + size = UndoRecordHeaderSize(uur->uur_info); + + /* Payload data size. */ + if ((uur->uur_info & UREC_INFO_PAYLOAD) != 0) + { + size += uur->uur_payload.len; + size += uur->uur_tuple.len; + } + + /* Add undo record length size. */ + size += sizeof(uint16); + + return size; +} + +/* + * Calculate the size of the undo record stored on the page. + */ +static inline Size +UndoRecordSizeOnPage(char *page_ptr) +{ + uint16 uur_info = ((UndoRecordHeader *) page_ptr)->urec_info; + Size size; + + /* Header size. */ + size = UndoRecordHeaderSize(uur_info); + + /* Payload data size. */ + if ((uur_info & UREC_INFO_PAYLOAD) != 0) + { + UndoRecordPayload *payload = (UndoRecordPayload *) (page_ptr + size); + + size += payload->urec_payload_len; + size += payload->urec_tuple_len; + } + + return size; +} + +/* + * Compute size of the Unpacked undo record in memory + */ +Size +UnpackedUndoRecordSize(UnpackedUndoRecord *uur) +{ + Size size; + + size = sizeof(UnpackedUndoRecord); + + /* Add payload size if record contains payload data. */ + if ((uur->uur_info & UREC_INFO_PAYLOAD) != 0) + { + size += uur->uur_payload.len; + size += uur->uur_tuple.len; + } + + return size; +} + +/* + * Initiate inserting an undo record. + * + * This function will initialize the context for inserting and undo record + * which will be inserted by calling InsertUndoData. + */ +void +BeginInsertUndo(UndoPackContext *ucontext, UnpackedUndoRecord *uur) +{ + ucontext->stage = UNDO_PACK_STAGE_HEADER; + ucontext->already_processed = 0; + ucontext->partial_bytes = 0; + + /* Copy undo record header. */ + ucontext->urec_hd.urec_type = uur->uur_type; + ucontext->urec_hd.urec_info = uur->uur_info; + + /* Copy undo record transaction header if it is present. */ + if ((uur->uur_info & UREC_INFO_TRANSACTION) != 0) + memcpy(&ucontext->urec_txn, uur->uur_txn, SizeOfUndoRecordTransaction); + + /* Copy rmid if present. */ + if ((uur->uur_info & UREC_INFO_RMID) != 0) + ucontext->urec_rmid = uur->uur_rmid; + + /* Copy reloid if present. */ + if ((uur->uur_info & UREC_INFO_RELOID) != 0) + ucontext->urec_reloid = uur->uur_reloid; + + /* Copy fxid if present. */ + if ((uur->uur_info & UREC_INFO_XID) != 0) + ucontext->urec_fxid = uur->uur_fxid; + + /* Copy cid if present. */ + if ((uur->uur_info & UREC_INFO_CID) != 0) + ucontext->urec_cid = uur->uur_cid; + + /* Copy undo record relation header if it is present. */ + if ((uur->uur_info & UREC_INFO_FORK) != 0) + ucontext->urec_fork = uur->uur_fork; + + /* Copy prev undo record pointer if it is present. */ + if ((uur->uur_info & UREC_INFO_PREVUNDO) != 0) + ucontext->urec_prevundo = uur->uur_prevundo; + + /* Copy undo record block header if it is present. */ + if ((uur->uur_info & UREC_INFO_BLOCK) != 0) + { + ucontext->urec_blk.urec_block = uur->uur_block; + ucontext->urec_blk.urec_offset = uur->uur_offset; + } + + /* Copy undo record log switch header if it is present. */ + if ((uur->uur_info & UREC_INFO_LOGSWITCH) != 0) + memcpy(&ucontext->urec_logswitch, uur->uur_logswitch, + SizeOfUndoRecordLogSwitch); + + /* Copy undo record payload header and data if it is present. */ + if ((uur->uur_info & UREC_INFO_PAYLOAD) != 0) + { + ucontext->urec_payload.urec_payload_len = uur->uur_payload.len; + ucontext->urec_payload.urec_tuple_len = uur->uur_tuple.len; + ucontext->urec_payloaddata = uur->uur_payload.data; + ucontext->urec_tupledata = uur->uur_tuple.data; + } + else + { + ucontext->urec_payload.urec_payload_len = 0; + ucontext->urec_payload.urec_tuple_len = 0; + } + + /* Compute undo record expected size and store in the context. */ + ucontext->undo_len = UndoRecordExpectedSize(uur); +} + +/* + * Insert the undo record into the input page from the unpack undo context. + * + * Caller can call this function multiple times until desired stage is reached. + * This will write the undo record into the page. + */ +void +InsertUndoData(UndoPackContext *ucontext, Page page, int starting_byte) +{ + char *writeptr = (char *) page + starting_byte; + char *endptr = (char *) page + BLCKSZ; + + switch (ucontext->stage) + { + case UNDO_PACK_STAGE_HEADER: + /* Insert undo record header. */ + if (!InsertUndoBytes((char *) &ucontext->urec_hd, + SizeOfUndoRecordHeader, &writeptr, endptr, + &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + ucontext->stage = UNDO_PACK_STAGE_TRANSACTION; + /* fall through */ + + case UNDO_PACK_STAGE_TRANSACTION: + if ((ucontext->urec_hd.urec_info & UREC_INFO_TRANSACTION) != 0) + { + /* Insert undo record transaction header. */ + if (!InsertUndoBytes((char *) &ucontext->urec_txn, + SizeOfUndoRecordTransaction, + &writeptr, endptr, + &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_RMID; + /* fall through */ + + case UNDO_PACK_STAGE_RMID: + /* Write rmid(if needed and not already done). */ + if ((ucontext->urec_hd.urec_info & UREC_INFO_RMID) != 0) + { + if (!InsertUndoBytes((char *) &(ucontext->urec_rmid), sizeof(RmgrId), + &writeptr, endptr, + &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_RELOID; + /* fall through */ + + case UNDO_PACK_STAGE_RELOID: + /* Write reloid(if needed and not already done). */ + if ((ucontext->urec_hd.urec_info & UREC_INFO_RELOID) != 0) + { + if (!InsertUndoBytes((char *) &(ucontext->urec_reloid), sizeof(Oid), + &writeptr, endptr, + &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_XID; + /* fall through */ + + case UNDO_PACK_STAGE_XID: + /* Write xid(if needed and not already done). */ + if ((ucontext->urec_hd.urec_info & UREC_INFO_XID) != 0) + { + if (!InsertUndoBytes((char *) &(ucontext->urec_fxid), sizeof(FullTransactionId), + &writeptr, endptr, + &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_CID; + /* fall through */ + + case UNDO_PACK_STAGE_CID: + /* Write cid(if needed and not already done). */ + if ((ucontext->urec_hd.urec_info & UREC_INFO_CID) != 0) + { + if (!InsertUndoBytes((char *) &(ucontext->urec_cid), sizeof(CommandId), + &writeptr, endptr, + &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_FORKNUM; + /* fall through */ + + case UNDO_PACK_STAGE_FORKNUM: + if ((ucontext->urec_hd.urec_info & UREC_INFO_FORK) != 0) + { + /* Insert undo record fork number. */ + if (!InsertUndoBytes((char *) &ucontext->urec_fork, + sizeof(ForkNumber), + &writeptr, endptr, + &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_PREVUNDO; + /* fall through */ + + case UNDO_PACK_STAGE_PREVUNDO: + if ((ucontext->urec_hd.urec_info & UREC_INFO_PREVUNDO) != 0) + { + /* Insert undo record blkprev. */ + if (!InsertUndoBytes((char *) &ucontext->urec_prevundo, + sizeof(UndoRecPtr), + &writeptr, endptr, + &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_BLOCK; + /* fall through */ + + case UNDO_PACK_STAGE_BLOCK: + if ((ucontext->urec_hd.urec_info & UREC_INFO_BLOCK) != 0) + { + /* Insert undo record block header. */ + if (!InsertUndoBytes((char *) &ucontext->urec_blk, + SizeOfUndoRecordBlock, + &writeptr, endptr, + &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_LOGSWITCH; + /* fall through */ + + case UNDO_PACK_STAGE_LOGSWITCH: + if ((ucontext->urec_hd.urec_info & UREC_INFO_LOGSWITCH) != 0) + { + /* Insert undo record transaction header. */ + if (!InsertUndoBytes((char *) &ucontext->urec_logswitch, + SizeOfUndoRecordLogSwitch, + &writeptr, endptr, + &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_PAYLOAD; + /* fall through */ + + case UNDO_PACK_STAGE_PAYLOAD: + if ((ucontext->urec_hd.urec_info & UREC_INFO_PAYLOAD) != 0) + { + /* Insert undo record payload header. */ + if (!InsertUndoBytes((char *) &ucontext->urec_payload, + SizeOfUndoRecordPayload, + &writeptr, endptr, + &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_PAYLOAD_DATA; + /* fall through */ + + case UNDO_PACK_STAGE_PAYLOAD_DATA: + { + int len = ucontext->urec_payload.urec_payload_len; + + if (len > 0) + { + /* Insert payload data. */ + if (!InsertUndoBytes((char *) ucontext->urec_payloaddata, + len, &writeptr, endptr, + &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_TUPLE_DATA; + } + /* fall through */ + + case UNDO_PACK_STAGE_TUPLE_DATA: + { + int len = ucontext->urec_payload.urec_tuple_len; + + if (len > 0) + { + /* Insert tuple data. */ + if (!InsertUndoBytes((char *) ucontext->urec_tupledata, + len, &writeptr, endptr, + &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_UNDO_LENGTH; + } + /* fall through */ + + case UNDO_PACK_STAGE_UNDO_LENGTH: + /* Insert undo length. */ + if (!InsertUndoBytes((char *) &ucontext->undo_len, + sizeof(uint16), &writeptr, endptr, + &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + + ucontext->stage = UNDO_PACK_STAGE_DONE; + /* fall through */ + + case UNDO_PACK_STAGE_DONE: + /* Nothing to be done. */ + break; + + default: + Assert(0); /* Invalid stage */ + } +} + +/* + * Skip inserting undo record + * + * Don't insert the actual undo record instead just update the context data + * so that if we need to insert the remaining partial record to the next + * block then we have right context. + */ +void +SkipInsertingUndoData(UndoPackContext *ucontext, int bytes_to_skip) +{ + switch (ucontext->stage) + { + case UNDO_PACK_STAGE_HEADER: + if (bytes_to_skip < SizeOfUndoRecordHeader) + { + ucontext->partial_bytes = bytes_to_skip; + return; + } + bytes_to_skip -= SizeOfUndoRecordHeader; + ucontext->stage = UNDO_PACK_STAGE_TRANSACTION; + /* fall through */ + + case UNDO_PACK_STAGE_TRANSACTION: + if ((ucontext->urec_hd.urec_info & UREC_INFO_TRANSACTION) != 0) + { + if (bytes_to_skip < SizeOfUndoRecordTransaction) + { + ucontext->partial_bytes = bytes_to_skip; + return; + } + bytes_to_skip -= SizeOfUndoRecordTransaction; + } + + ucontext->stage = UNDO_PACK_STAGE_RMID; + /* fall through */ + + case UNDO_PACK_STAGE_RMID: + /* Write rmid (if needed and not already done). */ + if ((ucontext->urec_hd.urec_info & UNDO_PACK_STAGE_RMID) != 0) + { + if (bytes_to_skip < (sizeof(RmgrId))) + { + ucontext->partial_bytes = bytes_to_skip; + return; + } + bytes_to_skip -= sizeof(RmgrId); + } + ucontext->stage = UNDO_PACK_STAGE_RELOID; + /* fall through */ + + case UNDO_PACK_STAGE_RELOID: + /* Write reloid (if needed and not already done). */ + if ((ucontext->urec_hd.urec_info & UNDO_PACK_STAGE_RELOID) != 0) + { + if (bytes_to_skip < sizeof(Oid)) + { + ucontext->partial_bytes = bytes_to_skip; + return; + } + bytes_to_skip -= sizeof(Oid); + } + ucontext->stage = UNDO_PACK_STAGE_XID; + /* fall through */ + + case UNDO_PACK_STAGE_XID: + /* Write xid (if needed and not already done). */ + if ((ucontext->urec_hd.urec_info & UNDO_PACK_STAGE_XID) != 0) + { + if (bytes_to_skip < (sizeof(TransactionId))) + { + ucontext->partial_bytes = bytes_to_skip; + return; + } + bytes_to_skip -= sizeof(TransactionId); + } + ucontext->stage = UNDO_PACK_STAGE_CID; + /* fall through */ + + case UNDO_PACK_STAGE_CID: + /* Write cid (if needed and not already done). */ + if ((ucontext->urec_hd.urec_info & UNDO_PACK_STAGE_CID) != 0) + { + if (bytes_to_skip < sizeof(CommandId)) + { + ucontext->partial_bytes = bytes_to_skip; + return; + } + bytes_to_skip -= sizeof(CommandId); + } + ucontext->stage = UNDO_PACK_STAGE_FORKNUM; + /* fall through */ + + case UNDO_PACK_STAGE_FORKNUM: + if ((ucontext->urec_hd.urec_info & UREC_INFO_FORK) != 0) + { + if (bytes_to_skip < sizeof(ForkNumber)) + { + ucontext->partial_bytes = bytes_to_skip; + return; + } + bytes_to_skip -= sizeof(ForkNumber); + } + + ucontext->stage = UNDO_PACK_STAGE_PREVUNDO; + /* fall through */ + + case UNDO_PACK_STAGE_PREVUNDO: + if ((ucontext->urec_hd.urec_info & UNDO_PACK_STAGE_PREVUNDO) != 0) + { + if (bytes_to_skip < sizeof(UndoRecPtr)) + { + ucontext->partial_bytes = bytes_to_skip; + return; + } + bytes_to_skip -= sizeof(UndoRecPtr); + } + ucontext->stage = UNDO_PACK_STAGE_BLOCK; + /* fall through */ + + case UNDO_PACK_STAGE_BLOCK: + if ((ucontext->urec_hd.urec_info & UREC_INFO_BLOCK) != 0) + { + if (bytes_to_skip < SizeOfUndoRecordBlock) + { + ucontext->partial_bytes = bytes_to_skip; + return; + } + bytes_to_skip -= SizeOfUndoRecordBlock; + } + ucontext->stage = UNDO_PACK_STAGE_LOGSWITCH; + /* fall through */ + + case UNDO_PACK_STAGE_LOGSWITCH: + if ((ucontext->urec_hd.urec_info & UREC_INFO_LOGSWITCH) != 0) + { + if (bytes_to_skip < SizeOfUndoRecordLogSwitch) + { + ucontext->partial_bytes = bytes_to_skip; + return; + } + bytes_to_skip -= SizeOfUndoRecordLogSwitch; + } + + ucontext->stage = UNDO_PACK_STAGE_PAYLOAD; + /* fall through */ + + case UNDO_PACK_STAGE_PAYLOAD: + /* Skip payload header. */ + if ((ucontext->urec_hd.urec_info & UREC_INFO_PAYLOAD) != 0) + { + if (bytes_to_skip < SizeOfUndoRecordPayload) + { + ucontext->partial_bytes = bytes_to_skip; + return; + } + bytes_to_skip -= SizeOfUndoRecordPayload; + } + ucontext->stage = UNDO_PACK_STAGE_PAYLOAD_DATA; + /* fall through */ + + case UNDO_PACK_STAGE_PAYLOAD_DATA: + if (ucontext->urec_payload.urec_payload_len > 0) + { + if (bytes_to_skip < ucontext->urec_payload.urec_payload_len) + { + ucontext->partial_bytes = bytes_to_skip; + return; + } + bytes_to_skip -= ucontext->urec_payload.urec_payload_len; + } + ucontext->stage = UNDO_PACK_STAGE_TUPLE_DATA; + /* fall through */ + + case UNDO_PACK_STAGE_TUPLE_DATA: + if (ucontext->urec_payload.urec_tuple_len > 0) + { + if (bytes_to_skip < ucontext->urec_payload.urec_tuple_len) + { + ucontext->partial_bytes = bytes_to_skip; + return; + } + bytes_to_skip -= ucontext->urec_payload.urec_tuple_len; + } + ucontext->stage = UNDO_PACK_STAGE_UNDO_LENGTH; + /* fall through */ + + case UNDO_PACK_STAGE_UNDO_LENGTH: + ucontext->stage = UNDO_PACK_STAGE_DONE; + /* fall through */ ; + + case UNDO_PACK_STAGE_DONE: + /* Nothing to be done. */ + break; + + default: + Assert(0); /* Invalid stage */ + } +} + +/* + * Write undo bytes from a particular source, but only to the extent that + * they weren't written previously and will fit. + * + * 'sourceptr' points to the source data, and 'sourcelen' is the length of + * that data in bytes. + * + * 'writeptr' points to the insertion point for these bytes, and is updated + * for whatever we write. The insertion point must not pass 'endptr', which + * represents the end of the buffer into which we are writing. + * + * 'my_bytes_written' is a pointer to the count of previous-written bytes + * from this and following structures in this undo record; that is, any + * bytes that are part of previous structures in the record have already + * been subtracted out. + * + * 'total_bytes_written' points to the count of all previously-written bytes, + * and must it must be updated for the bytes we write. + * + * The return value is false if we ran out of space before writing all + * the bytes, and otherwise true. + */ +static bool +InsertUndoBytes(char *sourceptr, int sourcelen, char **writeptr, char *endptr, + int *total_bytes_written, int *partial_write) +{ + int can_write; + int remaining; + + /* Compute number of bytes we can write. */ + remaining = sourcelen - *partial_write; + can_write = Min(remaining, endptr - *writeptr); + + /* Bail out if no bytes can be written. */ + if (can_write == 0) + return false; + + /* Copy the bytes we can write. */ + memcpy(*writeptr, sourceptr + *partial_write, can_write); + + /* Update bookkeeping information. */ + *writeptr += can_write; + *total_bytes_written += can_write; + + /* Could not read whole data so set the partial_read. */ + if (can_write < remaining) + { + *partial_write += can_write; + return false; + } + + /* Return true only if we wrote the whole thing. */ + *partial_write = 0; + return true; +} + +/* + * Initiate unpacking an undo record. + * + * This function will initialize the context for unpacking the undo record which + * will be unpacked by calling UnpackUndoData. + */ +void +BeginUnpackUndo(UndoPackContext *ucontext) +{ + ucontext->stage = UNDO_PACK_STAGE_HEADER; + ucontext->already_processed = 0; + ucontext->partial_bytes = 0; +} + +/* + * Read the undo record from the input page to the unpack undo context. + * + * Caller can call this function multiple times until desired stage is reached. + * This will read the undo record from the page and store the data into unpack + * undo context, which can be later copied to unpacked undo record by calling + * FinishUnpackUndo. + */ +void +UnpackUndoData(UndoPackContext *ucontext, Page page, int starting_byte) +{ + char *readptr = (char *) page + starting_byte; + char *endptr = (char *) page + BLCKSZ; + + switch (ucontext->stage) + { + case UNDO_PACK_STAGE_HEADER: + if (!ReadUndoBytes((char *) &ucontext->urec_hd, + SizeOfUndoRecordHeader, &readptr, endptr, + &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + ucontext->stage = UNDO_PACK_STAGE_TRANSACTION; + /* fall through */ + case UNDO_PACK_STAGE_TRANSACTION: + if ((ucontext->urec_hd.urec_info & UREC_INFO_TRANSACTION) != 0) + { + if (!ReadUndoBytes((char *) &ucontext->urec_txn, + SizeOfUndoRecordTransaction, + &readptr, endptr, &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_RMID; + /* fall through */ + case UNDO_PACK_STAGE_RMID: + if ((ucontext->urec_hd.urec_info & UREC_INFO_RMID) != 0) + { + if (!ReadUndoBytes((char *) &ucontext->urec_rmid, + sizeof(RmgrId), + &readptr, endptr, &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_RELOID; + /* fall through */ + case UNDO_PACK_STAGE_RELOID: + if ((ucontext->urec_hd.urec_info & UREC_INFO_RELOID) != 0) + { + if (!ReadUndoBytes((char *) &ucontext->urec_reloid, + sizeof(Oid), + &readptr, endptr, &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_XID; + /* fall through */ + case UNDO_PACK_STAGE_XID: + if ((ucontext->urec_hd.urec_info & UREC_INFO_XID) != 0) + { + if (!ReadUndoBytes((char *) &ucontext->urec_fxid, + sizeof(FullTransactionId), + &readptr, endptr, &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_CID; + /* fall through */ + case UNDO_PACK_STAGE_CID: + if ((ucontext->urec_hd.urec_info & UREC_INFO_CID) != 0) + { + if (!ReadUndoBytes((char *) &ucontext->urec_cid, + sizeof(CommandId), + &readptr, endptr, &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_FORKNUM; + /* fall through */ + case UNDO_PACK_STAGE_FORKNUM: + if ((ucontext->urec_hd.urec_info & UREC_INFO_FORK) != 0) + { + if (!ReadUndoBytes((char *) &ucontext->urec_fork, + sizeof(ForkNumber), + &readptr, endptr, &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_PREVUNDO; + /* fall through */ + case UNDO_PACK_STAGE_PREVUNDO: + if ((ucontext->urec_hd.urec_info & UREC_INFO_PREVUNDO) != 0) + { + if (!ReadUndoBytes((char *) &ucontext->urec_prevundo, + sizeof(UndoRecPtr), + &readptr, endptr, &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_BLOCK; + /* fall through */ + + case UNDO_PACK_STAGE_BLOCK: + if ((ucontext->urec_hd.urec_info & UREC_INFO_BLOCK) != 0) + { + if (!ReadUndoBytes((char *) &ucontext->urec_blk, + SizeOfUndoRecordBlock, + &readptr, endptr, &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_LOGSWITCH; + /* fall through */ + case UNDO_PACK_STAGE_LOGSWITCH: + if ((ucontext->urec_hd.urec_info & UREC_INFO_LOGSWITCH) != 0) + { + if (!ReadUndoBytes((char *) &ucontext->urec_logswitch, + SizeOfUndoRecordLogSwitch, + &readptr, endptr, &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_PAYLOAD; + /* fall through */ + case UNDO_PACK_STAGE_PAYLOAD: + /* Read payload header. */ + if ((ucontext->urec_hd.urec_info & UREC_INFO_PAYLOAD) != 0) + { + if (!ReadUndoBytes((char *) &ucontext->urec_payload, + SizeOfUndoRecordPayload, + &readptr, endptr, &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_PAYLOAD_DATA; + /* fall through */ + case UNDO_PACK_STAGE_PAYLOAD_DATA: + { + int len = ucontext->urec_payload.urec_payload_len; + + /* Allocate memory for the payload data if not already done. */ + if (len > 0) + { + if (ucontext->urec_payloaddata == NULL) + ucontext->urec_payloaddata = (char *) palloc(len); + + /* Read payload data. */ + if (!ReadUndoBytes((char *) ucontext->urec_payloaddata, len, + &readptr, endptr, &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + ucontext->stage = UNDO_PACK_STAGE_TUPLE_DATA; + /* fall through */ + } + case UNDO_PACK_STAGE_TUPLE_DATA: + { + int len = ucontext->urec_payload.urec_tuple_len; + + /* Allocate memory for the tuple data if not already done. */ + if (len > 0) + { + if (ucontext->urec_tupledata == NULL) + ucontext->urec_tupledata = (char *) palloc(len); + + /* Read tuple data. */ + if (!ReadUndoBytes((char *) ucontext->urec_tupledata, len, + &readptr, endptr, &ucontext->already_processed, + &ucontext->partial_bytes)) + return; + } + + ucontext->stage = UNDO_PACK_STAGE_DONE; + /* fall through */ + } + case UNDO_PACK_STAGE_DONE: + /* Nothing to be done. */ + break; + default: + Assert(0); /* Invalid stage */ + } + + return; +} + +/* + * Final step of unpacking the undo record. + * + * Copy the undo record data from the unpack undo context to the input unpacked + * undo record. + */ +void +FinishUnpackUndo(UndoPackContext *ucontext, UnpackedUndoRecord *uur) +{ + /* Copy undo record header. */ + uur->uur_type = ucontext->urec_hd.urec_type; + uur->uur_info = ucontext->urec_hd.urec_info; + + /* Copy undo record transaction header if it is present. */ + if ((uur->uur_info & UREC_INFO_TRANSACTION) != 0) + { + uur->uur_txn = palloc(SizeOfUndoRecordTransaction); + memcpy(uur->uur_txn, &ucontext->urec_txn, SizeOfUndoRecordTransaction); + } + + /* + * Copy the common field. All of these field must present in the final + * unpacked undo record. + */ + Assert((uur->uur_info & UREC_INFO_PAGE_COMMON) == UREC_INFO_PAGE_COMMON); + + uur->uur_rmid = ucontext->urec_rmid; + uur->uur_reloid = ucontext->urec_reloid; + uur->uur_fxid = ucontext->urec_fxid; + uur->uur_cid = ucontext->urec_cid; + + /* Copy undo record relation header if it is present. */ + if ((uur->uur_info & UREC_INFO_FORK) != 0) + uur->uur_fork = ucontext->urec_fork; + + /* Copy previous undo record pointer if it is present. */ + if ((uur->uur_info & UREC_INFO_PREVUNDO) != 0) + uur->uur_prevundo = ucontext->urec_prevundo; + + /* Copy undo record block header if it is present. */ + if ((uur->uur_info & UREC_INFO_BLOCK) != 0) + { + uur->uur_block = ucontext->urec_blk.urec_block; + uur->uur_offset = ucontext->urec_blk.urec_offset; + } + + /* Copy undo record log switch header if it is present. */ + if ((uur->uur_info & UREC_INFO_LOGSWITCH) != 0) + { + uur->uur_logswitch = palloc(SizeOfUndoRecordLogSwitch); + memcpy(uur->uur_logswitch, &ucontext->urec_logswitch, + SizeOfUndoRecordLogSwitch); + } + + /* Copy undo record payload header and data if it is present. */ + if ((uur->uur_info & UREC_INFO_PAYLOAD) != 0) + { + uur->uur_payload.len = ucontext->urec_payload.urec_payload_len; + uur->uur_tuple.len = ucontext->urec_payload.urec_tuple_len; + + /* Read payload data if its length is not 0. */ + if (uur->uur_payload.len != 0) + uur->uur_payload.data = ucontext->urec_payloaddata; + + /* Read tuple data if its length is not 0. */ + if (uur->uur_tuple.len != 0) + uur->uur_tuple.data = ucontext->urec_tupledata; + } +} + +/* + * Read undo bytes into a particular destination, + * + * 'destptr' points to the source data, and 'readlen' is the length of + * that data to be read in bytes. + * + * 'readptr' points to the read point for these bytes, and is updated + * for how much we read. The read point must not pass 'endptr', which + * represents the end of the buffer from which we are reading. + * + * 'partial_read' is a pointer to the count of previous partial read bytes + * + * 'total_bytes_read' points to the count of all previously-read bytes, + * and must likewise be updated for the bytes we read. + * + * nocopy if this flag is set true then it will just skip the readlen + * size in undo but it will not copy into the buffer. + * + * The return value is false if we ran out of space before read all + * the bytes, and otherwise true. + */ +static bool +ReadUndoBytes(char *destptr, int readlen, char **readptr, char *endptr, + int *total_bytes_read, int *partial_read) +{ + int can_read; + int remaining; + + /* Compute number of bytes we can read. */ + remaining = readlen - *partial_read; + can_read = Min(remaining, endptr - *readptr); + + /* Bail out if no bytes can be read. */ + if (can_read == 0) + return false; + + /* Copy the bytes we can read. */ + memcpy(destptr + *partial_read, *readptr, can_read); + + /* Update bookkeeping information. */ + *readptr += can_read; + *total_bytes_read += can_read; + + /* Could not read whole data so set the partial_read. */ + if (can_read < remaining) + { + *partial_read += can_read; + return false; + } + + /* Return true only if we wrote the whole thing. */ + *partial_read = 0; + + return true; +} + +/* + * Set uur_info for an UnpackedUndoRecord appropriately based on which + * fields are set. + * + * Other flags i.e UREC_INFO_TRANSACTION, UREC_INFO_PAGE_COMMON and, + * UREC_INFO_LOGSWITCH are directly set by the PrepareUndoInsert function. + */ +void +UndoRecordSetInfo(UnpackedUndoRecord *uur) +{ + /* + * If fork number is not the main fork then we need to store it in the + * undo record so set the flag. + */ + if (uur->uur_fork != MAIN_FORKNUM) + uur->uur_info |= UREC_INFO_FORK; + + /* If prevundo is valid undo record pointer then set the flag. */ + if (uur->uur_prevundo != InvalidUndoRecPtr) + uur->uur_info |= UREC_INFO_PREVUNDO; + + /* If the block number is valid then set the flag for the block header. */ + if (uur->uur_block != InvalidBlockNumber) + uur->uur_info |= UREC_INFO_BLOCK; + + /* + * Either of the payload or the tuple length is non-zero then we need the + * payload header. + */ + if (uur->uur_payload.len || uur->uur_tuple.len) + uur->uur_info |= UREC_INFO_PAYLOAD; +} diff --git a/src/backend/storage/page/bufpage.c b/src/backend/storage/page/bufpage.c index 6b49810..f5133c7 100644 --- a/src/backend/storage/page/bufpage.c +++ b/src/backend/storage/page/bufpage.c @@ -59,6 +59,34 @@ PageInit(Page page, Size pageSize, Size specialSize) /* p->pd_prune_xid = InvalidTransactionId; done by above MemSet */ } +/* + * UndoPageInit + * Initializes the contents of an undo page. + * Note that we don't calculate an initial checksum here; that's not done + * until it's time to write. + */ +void +UndoPageInit(Page page, Size pageSize, uint16 uur_info, uint16 record_offset, + uint16 tuple_len, uint16 payload_len) +{ + UndoPageHeader p = (UndoPageHeader) page; + + Assert(pageSize == BLCKSZ); + + /* Make sure all fields of page are zero, as well as unused space. */ + MemSet(p, 0, pageSize); + + p->pd_flags = 0; + p->pd_lower = SizeOfUndoPageHeaderData; + p->pd_upper = pageSize; + p->pd_special = pageSize; + p->uur_info = uur_info; + p->record_offset = record_offset; + p->tuple_len = tuple_len; + p->payload_len = payload_len; + PageSetPageSizeAndVersion(page, pageSize, PG_PAGE_LAYOUT_VERSION); +} + /* * PageIsVerified diff --git a/src/include/access/transam.h b/src/include/access/transam.h index 33fd052..cc00509 100644 --- a/src/include/access/transam.h +++ b/src/include/access/transam.h @@ -47,6 +47,7 @@ #define EpochFromFullTransactionId(x) ((uint32) ((x).value >> 32)) #define XidFromFullTransactionId(x) ((uint32) (x).value) #define U64FromFullTransactionId(x) ((x).value) +#define FullTransactionIdEquals(a, b) ((a).value == (b).value) #define FullTransactionIdPrecedes(a, b) ((a).value < (b).value) #define FullTransactionIdIsValid(x) TransactionIdIsValid(XidFromFullTransactionId(x)) #define InvalidFullTransactionId FullTransactionIdFromEpochAndXid(0, InvalidTransactionId) diff --git a/src/include/access/undoaccess.h b/src/include/access/undoaccess.h new file mode 100644 index 0000000..f7cfa9f --- /dev/null +++ b/src/include/access/undoaccess.h @@ -0,0 +1,121 @@ +/*------------------------------------------------------------------------- + * + * undoaccess.h + * entry points for inserting/fetching undo records + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/undoaccess.h + * + *------------------------------------------------------------------------- + */ +#ifndef UNDOACCESS_H +#define UNDOACCESS_H + +#include "access/undolog.h" +#include "access/undorecord.h" +#include "access/xlogdefs.h" +#include "catalog/pg_class.h" + +/* + * XXX Do we want to support undo tuple size which is more than the BLCKSZ + * if not than undo record can spread across 2 buffers at the max. + */ +#define MAX_BUFFER_PER_UNDO 2 + +/* + * Maximum number of the XactUndoRecordInfo for updating the transaction header. + * Usually it's 1 for updating next link of previous transaction's header + * if we are starting a new transaction. But, in some cases where the same + * transaction is spilled to the next log, we update our own transaction's + * header in previous undo log as well as the header of the previous transaction + * in the new log. + */ +#define MAX_XACT_UNDO_INFO 2 + +typedef struct PreparedUndoSpace PreparedUndoSpace; +typedef struct PreparedUndoBuffer PreparedUndoBuffer; + +/* + * Undo record element. Used for storing the group of undo record in a array + * using UndoBulkFetchRecord. + */ +typedef struct UndoRecInfo +{ + int index; /* Index of the element. For stable qsort. */ + UndoRecPtr urp; /* undo recptr (undo record location). */ + UnpackedUndoRecord *uur; /* actual undo record. */ +} UndoRecInfo; + +/* + * This structure holds the informations for updating the transaction's undo + * record header (first undo record of the transaction). We need to update the + * transaction header for various purposes a) updating the next undo record + * pointer for maintaining the transactions chain inside a undo log + * b) updating the undo apply progress in the transaction header. During + * prepare phase we will keep all the information handy in this structure and + * that will be used for updating the actual record inside the critical section. + */ +typedef struct XactUndoRecordInfo +{ + UndoRecPtr urecptr; /* Undo record pointer to be updated. */ + uint32 offset; /* offset in page where to start updating. */ + UndoRecPtr next; /* first urp of the next transaction which is + * be updated in transaction header */ + BlockNumber progress; /* undo apply action progress. */ + int idx_undo_buffers[MAX_BUFFER_PER_UNDO]; +} XactUndoRecordInfo; + +/* + * Context for preparing and inserting undo records.. + */ +typedef struct UndoRecordInsertContext +{ + UndoLogAllocContext alloc_context; + PreparedUndoSpace *prepared_undo; /* prepared undo. */ + PreparedUndoBuffer *prepared_undo_buffers; /* Buffers for prepared undo. */ + XactUndoRecordInfo xact_urec_info[MAX_XACT_UNDO_INFO]; /* Information for + * Updating transaction + * header. */ + UndoCompressionInfo undo_compression_info[UndoLogCategories]; /* Compression info. */ + int nprepared_undo; /* Number of prepared undo records. */ + int max_prepared_undo; /* Max prepared undo for this operation. */ + int nprepared_undo_buffer; /* Number of undo buffers. */ + int nxact_urec_info; /* Number of previous xact info. */ +} UndoRecordInsertContext; + +/* + * Context for fetching the required undo record. + */ +typedef struct UndoRecordFetchContext +{ + Buffer buffer; /* Previous undo record pinned buffer. */ + UndoRecPtr urp; /* Previous undo record pointer. */ +} UndoRecordFetchContext; + +extern void BeginUndoRecordInsert(UndoRecordInsertContext *context, + UndoLogCategory category, + int nprepared, + XLogReaderState *xlog_record); +extern UndoRecPtr PrepareUndoInsert(UndoRecordInsertContext *context, + UnpackedUndoRecord *urec, Oid dbid); +extern void InsertPreparedUndo(UndoRecordInsertContext *context); +extern void FinishUndoRecordInsert(UndoRecordInsertContext *context); +extern void BeginUndoFetch(UndoRecordFetchContext *context); +extern UnpackedUndoRecord *UndoFetchRecord(UndoRecordFetchContext *context, + UndoRecPtr urp); +extern void FinishUndoFetch(UndoRecordFetchContext *context); +extern void UndoRecordRelease(UnpackedUndoRecord *urec); +extern UndoRecInfo *UndoBulkFetchRecord(UndoRecPtr *from_urecptr, + UndoRecPtr to_urecptr, + int undo_apply_size, int *nrecords, + bool one_page); +extern void RegisterUndoLogBuffers(UndoRecordInsertContext *context, + uint8 first_block_id); +extern void UndoLogBuffersSetLSN(UndoRecordInsertContext *context, + XLogRecPtr recptr); +extern UndoRecPtr UndoGetPrevUndoRecptr(UndoRecPtr urp, Buffer buffer, + UndoLogCategory category); + +#endif /* UNDOINSERT_H */ diff --git a/src/include/access/undolog.h b/src/include/access/undolog.h index 1c79c1f..7ec4cb0 100644 --- a/src/include/access/undolog.h +++ b/src/include/access/undolog.h @@ -139,7 +139,7 @@ typedef int UndoLogNumber; (((uint64) (logno) << UndoLogOffsetBits) | (offset)) /* The number of unusable bytes in the header of each block. */ -#define UndoLogBlockHeaderSize SizeOfPageHeaderData +#define UndoLogBlockHeaderSize SizeOfUndoPageHeaderData /* The number of usable bytes we can store per block. */ #define UndoLogUsableBytesPerPage (BLCKSZ - UndoLogBlockHeaderSize) @@ -169,6 +169,10 @@ typedef int UndoLogNumber; #define UndoRecPtrGetPageOffset(urp) \ (UndoRecPtrGetOffset(urp) % BLCKSZ) +/* Compute the undo record pointer offset given the undo rec page offset and the block number. */ +#define UndoRecPageOffsetGetRecPtr(offset, blkno) \ + ((blkno * BLCKSZ) + offset) + /* Compare two undo checkpoint files to find the oldest file. */ #define UndoCheckPointFilenamePrecedes(file1, file2) \ (strcmp(file1, file2) < 0) @@ -207,7 +211,7 @@ typedef int UndoLogNumber; */ typedef struct UndoLogUnloggedMetaData { - UndoLogOffset insert; /* next insertion point (head) */ + UndoLogOffset insert; /* next insertion point (head) */ UndoLogOffset last_xact_start; /* last transaction's first byte in this log */ UndoLogOffset this_xact_start; /* this transaction's first byte in this log */ TransactionId xid; /* currently attached/writing xid */ @@ -352,7 +356,7 @@ extern PGDLLIMPORT undologtable_hash *undologtable_cache; static pg_attribute_always_inline UndoLogTableEntry * UndoLogGetTableEntry(UndoLogNumber logno) { - UndoLogTableEntry *entry; + UndoLogTableEntry *entry; /* Fast path. */ entry = undologtable_lookup(undologtable_cache, logno); diff --git a/src/include/access/undorecord.h b/src/include/access/undorecord.h new file mode 100644 index 0000000..0653267 --- /dev/null +++ b/src/include/access/undorecord.h @@ -0,0 +1,279 @@ +/*------------------------------------------------------------------------- + * + * undorecord.h + * encode and decode undo records + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/undorecord.h + * + *------------------------------------------------------------------------- + */ +#ifndef UNDORECORD_H +#define UNDORECORD_H + +#include "access/undolog.h" +#include "access/transam.h" +#include "lib/stringinfo.h" +#include "storage/block.h" +#include "storage/bufpage.h" +#include "storage/buf.h" +#include "storage/off.h" + +/* + * The below common information will be stored in the first undo record of the page. + * Every subsequent undo record will not store this information, if required this information + * will be retrieved from the first undo record of the page. + */ +typedef struct UndoCompressionInfo +{ + bool valid; /* Undo compression info is valid ? */ + UndoRecPtr last_urecptr; /* last undo rec */ + FullTransactionId fxid; /* transaction id */ + RmgrId rmid; /* rmgr ID */ + Oid reloid; /* relation OID */ + CommandId cid; /* command id */ +} UndoCompressionInfo; + +/* + * If UREC_INFO_TRANSACTION is set, an UndoRecordTransaction structure + * follows. + * If UREC_INFO_RMID is set, rmgr id follows. + * if UREC_INFO_RELOID is set, relation oid follows. + * If UREC_INFO_XID is set, full transaction id follows. + * If UREC_INFO_CID is set, command id follows. + * If UREC_INFO_FORK is set, fork number follows. + * If UREC_INFO_PREVUNDO is set, previous undo record pointer follows. + * If UREC_INFO_BLOCK is set, an UndoRecordBlock structure follows. + * If UREC_INFO_LOGSWITCH is set, an UndoRecordLogSwitch structure follows. + * If UREC_INFO_PAYLOAD is set, an UndoRecordPayload structure follows. + * + * When (as will often be the case) multiple structures are present, they + * appear in the same order in which the constants are defined here. That is, + * UndoRecordTransaction appears first. + */ +#define UREC_INFO_TRANSACTION 0x001 +#define UREC_INFO_RMID 0x002 +#define UREC_INFO_RELOID 0x004 +#define UREC_INFO_XID 0x008 +#define UREC_INFO_CID 0x010 +#define UREC_INFO_FORK 0x020 +#define UREC_INFO_PREVUNDO 0x040 +#define UREC_INFO_BLOCK 0x080 +#define UREC_INFO_LOGSWITCH 0x100 +#define UREC_INFO_PAYLOAD 0x200 + +#define UREC_INFO_PAGE_COMMON (UREC_INFO_RMID | UREC_INFO_RELOID | UREC_INFO_XID | UREC_INFO_CID) + +/* + * Every undo record begins with an UndoRecordHeader structure, which is + * followed by the additional structures indicated by the contents of + * urec_info. All structures are packed into the alignment without padding + * bytes, and the undo record itself need not be aligned either, so care + * must be taken when reading the header. + */ +typedef struct UndoRecordHeader +{ + uint8 urec_type; /* record type code */ + uint16 urec_info; /* flag bits */ +} UndoRecordHeader; + +#define SizeOfUndoRecordHeader \ + (offsetof(UndoRecordHeader, urec_info) + sizeof(uint16)) + +/* + * Information for a transaction to which this undo belongs. This + * also stores the dbid and the progress of the undo apply during rollback. + */ +typedef struct UndoRecordTransaction +{ + /* + * Undo block number where we need to start reading the undo for applying + * the undo action. InvalidBlockNumber means undo applying hasn't + * started for the transaction and MaxBlockNumber mean undo completely + * applied. And, any other block number means we have applied partial undo + * so next we can start from this block. + */ + BlockNumber urec_progress; + Oid urec_dbid; /* database id */ + UndoRecPtr urec_next; /* urec pointer of the next transaction */ +} UndoRecordTransaction; + +#define SizeOfUndoRecordTransaction \ + (offsetof(UndoRecordTransaction, urec_next) + sizeof(UndoRecPtr)) + +/* + * Information for a block to which this record pertains. + */ +typedef struct UndoRecordBlock +{ + BlockNumber urec_block; /* block number */ + OffsetNumber urec_offset; /* offset number */ +} UndoRecordBlock; + +#define SizeOfUndoRecordBlock \ + (offsetof(UndoRecordBlock, urec_offset) + sizeof(OffsetNumber)) + +/* + * Information of the transaction's undo in the previous log. If a transaction + * is split across the undo logs then this header will be included in the first + * undo record of the transaction in next log. + */ +typedef struct UndoRecordLogSwitch +{ + UndoRecPtr urec_prevurp; /* Transaction's last undo record pointer in + * the previous undo log. */ + UndoRecPtr urec_prevlogstart; /* Transaction's first undo record pointer + * in previous undo log. */ +} UndoRecordLogSwitch; + +#define SizeOfUndoRecordLogSwitch \ + (offsetof(UndoRecordLogSwitch, urec_prevlogstart) + sizeof(UndoRecPtr)) + +/* + * Information about the amount of payload data and tuple data present + * in this record. The payload bytes immediately follow the structures + * specified by flag bits in urec_info, and the tuple bytes follow the + * payload bytes. + */ +typedef struct UndoRecordPayload +{ + uint16 urec_payload_len; /* # of payload bytes */ + uint16 urec_tuple_len; /* # of tuple bytes */ +} UndoRecordPayload; + +#define SizeOfUndoRecordPayload \ + (offsetof(UndoRecordPayload, urec_tuple_len) + sizeof(uint16)) + +typedef enum UndoPackStage +{ + UNDO_PACK_STAGE_HEADER, /* We have not yet processed even the record + * header; we need to do that next. */ + UNDO_PACK_STAGE_TRANSACTION, /* The next thing to be processed is the + * transaction details, if present. */ + UNDO_PACK_STAGE_RMID, /* The next thing to be processed is the rmid + * if present */ + + UNDO_PACK_STAGE_RELOID, /* The next thing to be processed is the + * reloid if present */ + + UNDO_PACK_STAGE_XID, /* The next thing to be processed is the xid + * if present */ + + UNDO_PACK_STAGE_CID, /* The next thing to be processed is the cid + * if present */ + + UNDO_PACK_STAGE_FORKNUM, /* The next thing to be processed is the + * relation fork number, if present. */ + UNDO_PACK_STAGE_PREVUNDO, /* The next thing to be processed is the prev + * undo info. */ + + UNDO_PACK_STAGE_BLOCK, /* The next thing to be processed is the block + * details, if present. */ + UNDO_PACK_STAGE_LOGSWITCH, /* The next thing to be processed is the log + * switch details. */ + UNDO_PACK_STAGE_PAYLOAD, /* The next thing to be processed is the + * payload details, if present */ + UNDO_PACK_STAGE_PAYLOAD_DATA, /* The next thing to be processed is the + * payload data */ + UNDO_PACK_STAGE_TUPLE_DATA, /* The next thing to be processed is the tuple + * data */ + UNDO_PACK_STAGE_UNDO_LENGTH, /* Next thing to processed is undo length. */ + + UNDO_PACK_STAGE_DONE /* complete */ +} UndoPackStage; + +/* + * Undo record context for inserting/unpacking undo record. This will hold + * intermediate state of undo record processed so far. + */ +typedef struct UndoPackContext +{ + UndoRecordHeader urec_hd; /* Main header */ + UndoRecordTransaction urec_txn; /* Transaction header */ + + RmgrId urec_rmid; /* rmgrid */ + Oid urec_reloid; /* relation OID */ + + /* + * Transaction id that has modified the tuple for which this undo record + * is written. We use this to skip the undo records. See comments atop + * function UndoFetchRecord. + */ + FullTransactionId urec_fxid; /* Transaction id */ + CommandId urec_cid; /* command id */ + + ForkNumber urec_fork; /* Relation fork number */ + UndoRecPtr urec_prevundo; /* Block prev */ + UndoRecordBlock urec_blk; /* Block header */ + UndoRecordLogSwitch urec_logswitch; /* Log switch header */ + UndoRecordPayload urec_payload; /* Payload data */ + char *urec_payloaddata; + char *urec_tupledata; + uint16 undo_len; /* Length of the undo record. */ + int already_processed; /* Number of bytes read/written so far */ + int partial_bytes; /* Number of partial bytes read/written */ + UndoPackStage stage; /* Undo pack stage */ +} UndoPackContext; + +/* + * Information that can be used to create an undo record or that can be + * extracted from one previously created. The raw undo record format is + * difficult to manage, so this structure provides a convenient intermediate + * form that is easier for callers to manage. + * + * When creating an undo record from an UnpackedUndoRecord, caller should + * set uur_info to 0. It will be initialized by the first call to + * UndoRecordSetInfo or InsertUndoRecord. We do set it in + * UndoRecordAllocate for transaction specific header information. + * + * When an undo record is decoded into an UnpackedUndoRecord, all fields + * will be initialized, but those for which no information is available + * will be set to invalid or default values, as appropriate. + */ +typedef struct UnpackedUndoRecord +{ + RmgrId uur_rmid; /* rmgr ID */ + uint8 uur_type; /* record type code */ + uint16 uur_info; /* flag bits */ + Oid uur_reloid; /* relation OID */ + CommandId uur_cid; /* command id */ + ForkNumber uur_fork; /* fork number */ + UndoRecPtr uur_prevundo; /* byte offset of previous undo for block */ + BlockNumber uur_block; /* block number */ + OffsetNumber uur_offset; /* offset number */ + FullTransactionId uur_fxid; /* transaction id */ + StringInfoData uur_payload; /* payload bytes */ + StringInfoData uur_tuple; /* tuple bytes */ + + /* + * Below header will be internally set by the undo layer. Above this all + * information should be set by the caller. + */ + UndoRecordTransaction *uur_txn; /* Transaction header, included in the + * first record of the transaction in a + * undo log. */ + UndoRecordLogSwitch *uur_logswitch; /* Log switch header, included in the + * first record of the transaction + * only after undo log is switched + * during a transaction. */ +} UnpackedUndoRecord; + +extern Size UndoRecordHeaderSize(uint16 uur_info); +extern Size UndoRecordExpectedSize(UnpackedUndoRecord *uur); +extern Size UnpackedUndoRecordSize(UnpackedUndoRecord *uur); +extern void BeginInsertUndo(UndoPackContext *ucontext, + UnpackedUndoRecord *uur); +extern void InsertUndoData(UndoPackContext *ucontext, Page page, + int starting_byte); +extern void SkipInsertingUndoData(UndoPackContext *ucontext, + int bytes_to_skip); +extern void BeginUnpackUndo(UndoPackContext *ucontext); +extern void UnpackUndoData(UndoPackContext *ucontext, Page page, + int starting_byte); +extern void FinishUnpackUndo(UndoPackContext *ucontext, + UnpackedUndoRecord *uur); +extern void UndoRecordSetInfo(UnpackedUndoRecord *uur); + +#endif /* UNDORECORD_H */ diff --git a/src/include/storage/bufpage.h b/src/include/storage/bufpage.h index 34b68ad..93d108c 100644 --- a/src/include/storage/bufpage.h +++ b/src/include/storage/bufpage.h @@ -216,6 +216,43 @@ typedef PageHeaderData *PageHeader; #define SizeOfPageHeaderData (offsetof(PageHeaderData, pd_linp)) /* + * Same as PageHeaderData + some additional information to detect partial + * undo record on a undo page. + * + * FIXME : for undo page do we need to keep all the information which is + * required for the PageHeaderData e.g. pd_lower, pd_upper, pd_special? + */ +typedef struct UndoPageHeaderData +{ + /* XXX LSN is member of *any* block, not only page-organized ones */ + PageXLogRecPtr pd_lsn; /* LSN: next byte after last byte of xlog + * record for last change to this page */ + uint16 pd_checksum; /* checksum */ + uint16 pd_flags; /* flag bits, see below */ + LocationIndex pd_lower; /* offset to start of free space */ + LocationIndex pd_upper; /* offset to end of free space */ + LocationIndex pd_special; /* offset to start of special space */ + uint16 pd_pagesize_version; + + /* + * Below fields required for computing the offset of the first complete + * record on a undo page, which will be used for the undo record compression + * and undo page consistency checking. + */ + uint16 uur_info; /* uur_info field of the partial record. */ + uint16 record_offset; /* offset of the partial undo record. */ + uint16 tuple_len; /* Length of the tuple data in the partial + * record. */ + uint16 payload_len; /* Length of the payload data in the partial + * record. */ +} UndoPageHeaderData; + +typedef UndoPageHeaderData *UndoPageHeader; + +#define SizeOfUndoPageHeaderData (offsetof(UndoPageHeaderData, payload_len) + \ + sizeof(uint16)) + +/* * PageIsEmpty * returns true iff no itemid has been allocated on the page */ @@ -419,6 +456,9 @@ do { \ ((is_heap) ? PAI_IS_HEAP : 0)) extern void PageInit(Page page, Size pageSize, Size specialSize); +extern void UndoPageInit(Page page, Size pageSize, uint16 uur_info, + uint16 record_offset, uint16 tuple_len, + uint16 payload_len); extern bool PageIsVerified(Page page, BlockNumber blkno); extern OffsetNumber PageAddItemExtended(Page page, Item item, Size size, OffsetNumber offsetNumber, int flags); -- 1.8.3.1 [application/octet-stream] 0008-undo-page-consistency-checker.patch (4.4K, ../../CAA4eK1+McY0qGaak0AHyzdgAn+F6dyxcpDwp9ifGg=1WVDadeQ@mail.gmail.com/9-0008-undo-page-consistency-checker.patch) download | inline diff: From 78472d023fa481441dacabc46d689d9dd5c21a00 Mon Sep 17 00:00:00 2001 From: Dilip Kumar <[email protected]> Date: Thu, 4 Jul 2019 11:52:55 +0530 Subject: [PATCH 08/13] undo page consistency checker Patch provide a mechanism for masking the cid bit in undo pages so that consistecy checker function can compared the undo pages. Actual consistency check should be called under the RM's consistency checker function who is writing the undo because undo pages will be registered under that RM's WAL Dilip Kumar with help from Amit Khandekar and Rafia Sabih --- src/backend/access/undo/undorecord.c | 110 +++++++++++++++++++++++++++++++++++ src/include/access/undorecord.h | 1 + 2 files changed, 111 insertions(+) diff --git a/src/backend/access/undo/undorecord.c b/src/backend/access/undo/undorecord.c index a44bfbd..5699153 100755 --- a/src/backend/access/undo/undorecord.c +++ b/src/backend/access/undo/undorecord.c @@ -1049,3 +1049,113 @@ UndoRecordSetInfo(UnpackedUndoRecord *uur) if (uur->uur_payload.len || uur->uur_tuple.len) uur->uur_info |= UREC_INFO_PAYLOAD; } + +/* + * Get the offset of cid information in undo record. + */ +static Size +get_undo_rec_cid_offset(uint16 urec_info) +{ + Size offset_size = SizeOfUndoRecordHeader; + + if ((urec_info & UREC_INFO_TRANSACTION) != 0) + offset_size += SizeOfUndoRecordTransaction; + + if ((urec_info & UREC_INFO_RMID) != 0) + offset_size += sizeof(RmgrId); + + if ((urec_info & UREC_INFO_RELOID) != 0) + offset_size += sizeof(Oid); + + if ((urec_info & UREC_INFO_XID) != 0) + offset_size += sizeof(FullTransactionId); + + return offset_size; +} + +/* + * Mask a undo page before performing consistency checks on it. + */ +void +mask_undo_page(char *pagedata) +{ + Page page = (Page) pagedata; + char *page_end = pagedata + PageGetPageSize(page); + char *next_record; + int cid_offset; + UndoPageHeader phdr = (UndoPageHeader) page; + + next_record = (char *) page + SizeOfUndoPageHeaderData; + + /* + * If record_offset is non-zero value in the page header that means page + * has a partial record. + */ + if (phdr->record_offset != 0) + { + Size partial_rec_size; + + /* Calculate the size of the partial record. */ + partial_rec_size = UndoRecordHeaderSize(phdr->uur_info) + + phdr->tuple_len + phdr->payload_len - + phdr->record_offset; + if ((phdr->uur_info & UREC_INFO_CID) != 0) + { + cid_offset = get_undo_rec_cid_offset(phdr->uur_info); + + /* + * We just want to mask the cid in the undo record header. So + * only if the partial record in the current page include the undo + * record header then we need to mask the cid bytes in this page. + * Otherwise, directly jump to the next record. + */ + if (phdr->record_offset < (cid_offset + sizeof(CommandId))) + { + char *cid_data; + Size mask_size; + + mask_size = Min(cid_offset - phdr->record_offset, + sizeof(CommandId)); + + cid_data = next_record + cid_offset - phdr->record_offset; + memset(&cid_data, MASK_MARKER, mask_size); + } + } + + next_record += partial_rec_size; + } + + /* + * Process the undo record of the page and mask their cid filed. + */ + while (next_record < page_end) + { + UndoRecordHeader *header = (UndoRecordHeader *) next_record; + + /* If this undo record has cid present, then mask it */ + if ((header->urec_info & UREC_INFO_CID) != 0) + { + cid_offset = get_undo_rec_cid_offset(header->urec_info); + + /* + * If this is not complete record then check whether cid is on + * this page or not. If not then we are done with this page. + */ + if ((next_record + cid_offset + sizeof(CommandId)) > page_end) + { + int mask_size = page_end - next_record - cid_offset; + + if (mask_size > 0) + memset(next_record + cid_offset, MASK_MARKER, mask_size); + break; + } + else + { + /* Mask cid */ + memset(next_record + cid_offset, MASK_MARKER, sizeof(CommandId)); + } + } + /* Go to next record. */ + next_record += UndoRecordSizeOnPage(next_record); + } +} diff --git a/src/include/access/undorecord.h b/src/include/access/undorecord.h index 0653267..6a2c5cc 100644 --- a/src/include/access/undorecord.h +++ b/src/include/access/undorecord.h @@ -276,4 +276,5 @@ extern void FinishUnpackUndo(UndoPackContext *ucontext, UnpackedUndoRecord *uur); extern void UndoRecordSetInfo(UnpackedUndoRecord *uur); +extern void mask_undo_page(char *pagedata); #endif /* UNDORECORD_H */ -- 1.8.3.1 [application/octet-stream] 0009-Extend-binary-heap-functionality.patch (5.3K, ../../CAA4eK1+McY0qGaak0AHyzdgAn+F6dyxcpDwp9ifGg=1WVDadeQ@mail.gmail.com/10-0009-Extend-binary-heap-functionality.patch) download | inline diff: From 85a0f0fe2d10dc524d0d52e53969ab02c0694042 Mon Sep 17 00:00:00 2001 From: Amit Kapila <[email protected]> Date: Mon, 27 May 2019 14:02:23 +0530 Subject: [PATCH 09/13] Extend binary heap functionality. Add the routines to allocate binary heap in shared memory and to remove nth element from binray heap. This routines will be used by latter commit to add support for undo workers. Author: Kuntal Ghosh and Amit Kapila --- src/backend/lib/binaryheap.c | 118 +++++++++++++++++++++++++++++++++++++++++++ src/include/lib/binaryheap.h | 12 ++++- 2 files changed, 128 insertions(+), 2 deletions(-) diff --git a/src/backend/lib/binaryheap.c b/src/backend/lib/binaryheap.c index a2c8967..5f7454d 100644 --- a/src/backend/lib/binaryheap.c +++ b/src/backend/lib/binaryheap.c @@ -16,6 +16,7 @@ #include <math.h> #include "lib/binaryheap.h" +#include "storage/shmem.h" static void sift_down(binaryheap *heap, int node_off); static void sift_up(binaryheap *heap, int node_off); @@ -48,6 +49,36 @@ binaryheap_allocate(int capacity, binaryheap_comparator compare, void *arg) } /* + * binaryheap_allocate_shm + * + * It works same as binaryheap_allocate except that the heap will be created + * in shared memory. + */ +binaryheap * +binaryheap_allocate_shm(const char *name, int capacity, + binaryheap_comparator compare, void *arg) +{ + Size sz; + binaryheap *heap; + bool foundBHeap; + + sz = binaryheap_shmem_size(capacity); + heap = (binaryheap *) ShmemInitStruct(name, sz, &foundBHeap); + + if (!foundBHeap) + { + heap->bh_space = capacity; + heap->bh_compare = compare; + heap->bh_arg = arg; + + heap->bh_size = 0; + heap->bh_has_heap_property = true; + } + + return heap; +} + +/* * binaryheap_reset * * Resets the heap to an empty state, losing its data content but not the @@ -212,6 +243,79 @@ binaryheap_replace_first(binaryheap *heap, Datum d) } /* + * binaryheap_nth + * + * Returns a pointer to the nth (0-based) node in the heap without modifying + * the heap in O(1). The caller must ensure that this routine is not used on + * an empty heap and is not called with n greater than or equal to the heap + * size. + */ +Datum +binaryheap_nth(binaryheap *heap, int n) +{ + Assert(!binaryheap_empty(heap)); + Assert(n < heap->bh_size); + return heap->bh_nodes[n]; +} + +/* + * binaryheap_remove_nth + * + * Removes the nth node (0-based) in the heap and returns a + * pointer to it after rebalancing the heap. The caller must ensure + * that this routine is not used on an empty heap. O(log n) worst + * case. + */ +Datum +binaryheap_remove_nth(binaryheap *heap, int n) +{ + Assert(!binaryheap_empty(heap) && heap->bh_has_heap_property); + Assert(n < heap->bh_size); + + + if (n == heap->bh_size - 1) + { + heap->bh_size--; + return heap->bh_nodes[heap->bh_size]; + } + + swap_nodes(heap, n, heap->bh_size - 1); + heap->bh_size--; + sift_down(heap, n); + + return heap->bh_nodes[heap->bh_size]; +} + +/* + * binaryheap_remove_nth_unordered + * + * Removes the nth node (0-based) in the heap and returns a pointer to it in + * O(1) without preserving the heap property. This is a convenience routine + * to remove elements quickly. To obtain a valid heap, one must call + * binaryheap_build() afterwards. The caller must ensure that this routine is + * not used on an empty heap. + */ +Datum +binaryheap_remove_nth_unordered(binaryheap *heap, int n) +{ + Assert(!binaryheap_empty(heap)); + Assert(n < heap->bh_size); + + heap->bh_has_heap_property = false; + + if (n == heap->bh_size - 1) + { + heap->bh_size--; + return heap->bh_nodes[heap->bh_size]; + } + + swap_nodes(heap, n, heap->bh_size - 1); + heap->bh_size--; + + return heap->bh_nodes[heap->bh_size]; +} + +/* * Swap the contents of two nodes. */ static inline void @@ -305,3 +409,17 @@ sift_down(binaryheap *heap, int node_off) node_off = swap_off; } } + +/* + * Compute the size required by binary heap structure. + */ +Size +binaryheap_shmem_size(int capacity) +{ + Size sz; + + sz = add_size(offsetof(binaryheap, bh_nodes), + mul_size(sizeof(Datum), capacity)); + + return sz; +} diff --git a/src/include/lib/binaryheap.h b/src/include/lib/binaryheap.h index 21f96b9..ed9e8e8 100644 --- a/src/include/lib/binaryheap.h +++ b/src/include/lib/binaryheap.h @@ -38,8 +38,11 @@ typedef struct binaryheap } binaryheap; extern binaryheap *binaryheap_allocate(int capacity, - binaryheap_comparator compare, - void *arg); + binaryheap_comparator compare, + void *arg); +extern binaryheap *binaryheap_allocate_shm(const char *name, int capacity, + binaryheap_comparator compare, + void *arg); extern void binaryheap_reset(binaryheap *heap); extern void binaryheap_free(binaryheap *heap); extern void binaryheap_add_unordered(binaryheap *heap, Datum d); @@ -48,7 +51,12 @@ extern void binaryheap_add(binaryheap *heap, Datum d); extern Datum binaryheap_first(binaryheap *heap); extern Datum binaryheap_remove_first(binaryheap *heap); extern void binaryheap_replace_first(binaryheap *heap, Datum d); +extern Datum binaryheap_nth(binaryheap *heap, int n); +extern Datum binaryheap_remove_nth(binaryheap *heap, int n); +extern Datum binaryheap_remove_nth_unordered(binaryheap *heap, int n); +extern Size binaryheap_shmem_size(int capacity); #define binaryheap_empty(h) ((h)->bh_size == 0) +#define binaryheap_cur_size(h) ((h)->bh_size) #endif /* BINARYHEAP_H */ -- 1.8.3.1 [application/octet-stream] 0010-Infrastructure-to-register-and-fetch-undo-action-req.patch (66.8K, ../../CAA4eK1+McY0qGaak0AHyzdgAn+F6dyxcpDwp9ifGg=1WVDadeQ@mail.gmail.com/11-0010-Infrastructure-to-register-and-fetch-undo-action-req.patch) download | inline diff: From 95d10fb308e3ec6ac8a7b4b5e7af78f6825f4dc8 Mon Sep 17 00:00:00 2001 From: Amit Kapila <[email protected]> Date: Thu, 13 Jun 2019 15:10:06 +0530 Subject: [PATCH 10/13] Infrastructure to register and fetch undo action requests. This infrasture provides a way to allow execution of undo actions. One might think that we can always execute undo actions on error or explicit rollabck by user, however there are cases when that is not posssible. For example, (a) if the system crash while doing operation, then after startup, we need a way to perform undo actions; (b) If we get error while performing undo actions. Apart from this, when there are large rollback requests, then it is quite inefficient to perform all the undo actions and then return control to user. To allow efficient execution of the undo actions, we create three queues and a hash table for the rollback requests. A Xid based priority queue which will allow us to process the requests of older transactions and help us to move oldesdXidHavingUnappliedUndo (this is a xid-horizon below which all the transactions are visible) forward. A size-based queue which will help us to perform the rollbacks of larger aborts in a timely fashion so that we don't get stuck while processing them during discard of the logs. An error queue to hold the requests for transactions that failed to apply its undo. The rollback hash table is used to avoid duplicate undo requests by backends and discard worker. Amit Kapila and Kuntal Ghosh, design idea by Andres Freund. --- src/backend/access/undo/Makefile | 2 +- src/backend/access/undo/undoaccess.c | 50 +- src/backend/access/undo/undorequest.c | 1647 +++++++++++++++++++++++++ src/backend/storage/lmgr/lwlocknames.txt | 1 + src/backend/storage/lmgr/proc.c | 2 + src/backend/utils/init/postinit.c | 14 + src/backend/utils/misc/guc.c | 22 + src/backend/utils/misc/postgresql.conf.sample | 8 + src/include/access/transam.h | 1 + src/include/access/undoaccess.h | 3 + src/include/access/undorequest.h | 231 ++++ src/include/miscadmin.h | 1 + src/include/storage/proc.h | 2 + 13 files changed, 1982 insertions(+), 2 deletions(-) create mode 100644 src/backend/access/undo/undorequest.c create mode 100644 src/include/access/undorequest.h diff --git a/src/backend/access/undo/Makefile b/src/backend/access/undo/Makefile index 049a416..7327502 100644 --- a/src/backend/access/undo/Makefile +++ b/src/backend/access/undo/Makefile @@ -12,6 +12,6 @@ subdir = src/backend/access/undo top_builddir = ../../../.. include $(top_builddir)/src/Makefile.global -OBJS = undoaccess.o undolog.o undorecord.o +OBJS = undoaccess.o undolog.o undorecord.o undorequest.o include $(top_srcdir)/src/backend/common.mk diff --git a/src/backend/access/undo/undoaccess.c b/src/backend/access/undo/undoaccess.c index a8cf469..4ffec58 100644 --- a/src/backend/access/undo/undoaccess.c +++ b/src/backend/access/undo/undoaccess.c @@ -46,6 +46,7 @@ #include "access/undorecord.h" #include "access/undoaccess.h" #include "access/undolog_xlog.h" +#include "access/undorequest.h" #include "access/xact.h" #include "access/xlog.h" #include "access/xlogutils.h" @@ -754,7 +755,7 @@ PrepareUndoInsert(UndoRecordInsertContext *context, { urec->uur_txn = palloc(SizeOfUndoRecordTransaction); urec->uur_txn->urec_dbid = dbid; - urec->uur_txn->urec_progress = InvalidBlockNumber; + urec->uur_txn->urec_progress = XACT_APPLY_PROGRESS_NOT_STARTED; urec->uur_txn->urec_next = InvalidUndoRecPtr; } else @@ -1752,3 +1753,50 @@ UndoGetPrevUndoRecptr(UndoRecPtr urp, Buffer buffer, /* calculate the previous undo record pointer */ return MakeUndoRecPtr(logno, offset - prevlen); } + +/* + * Returns the undo record pointer corresponding to first record in the given + * block. + */ +UndoRecPtr +UndoBlockGetFirstUndoRecord(BlockNumber blkno, UndoRecPtr urec_ptr, + UndoLogCategory category) +{ + Buffer buffer; + Page page; + UndoPageHeader phdr; + RelFileNode rnode; + UndoLogOffset log_cur_off; + Size partial_rec_size; + int offset_cur_page; + + if (!BlockNumberIsValid(blkno)) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("invalid undo block number"))); + + UndoRecPtrAssignRelFileNode(rnode, urec_ptr); + + buffer = ReadBufferWithoutRelcache(rnode, UndoLogForkNum, blkno, + RBM_NORMAL, NULL, + RelPersistenceForUndoLogCategory(category)); + + LockBuffer(buffer, BUFFER_LOCK_SHARE); + + page = BufferGetPage(buffer); + phdr = (UndoPageHeader)page; + + /* Calculate the size of the partial record. */ + partial_rec_size = UndoRecordHeaderSize(phdr->uur_info) + + phdr->tuple_len + phdr->payload_len - + phdr->record_offset; + + /* calculate the offset in current log. */ + offset_cur_page = SizeOfUndoPageHeaderData + partial_rec_size; + log_cur_off = (blkno * BLCKSZ) + offset_cur_page; + + UnlockReleaseBuffer(buffer); + + /* calculate the undo record pointer based on current offset in log. */ + return MakeUndoRecPtr(UndoRecPtrGetLogNo(urec_ptr), log_cur_off); +} diff --git a/src/backend/access/undo/undorequest.c b/src/backend/access/undo/undorequest.c new file mode 100644 index 0000000..530887a --- /dev/null +++ b/src/backend/access/undo/undorequest.c @@ -0,0 +1,1647 @@ +/*------------------------------------------------------------------------- + * + * undorequest.c + * This contains routines to register and fetch undo action requests. + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/backend/access/undo/undorequest.c + * + * To increase the efficiency of the rollbacks, we create three queues and + * a hash table for the rollback requests. A Xid based priority queue which + * will allow us to process the requests of older transactions and help us + * to move oldesdXidHavingUndo forward. A size-based queue which will help + * us to perform the rollbacks of larger aborts in a timely fashion, so that + * we don't get stuck while processing them during discard of the logs. + * An error queue to hold the requests for transactions that failed to apply + * its undo. The rollback hash table is used to avoid duplicate undo requests + * by backends and discard worker. The table must be able to accommodate all + * active undo requests. The undo requests must appear in both xid and size + * requests queues or neither. As of now we, process the requests from these + * queues in a round-robin fashion to give equal priority to all three type + * of requests. + * + * The rollback requests exceeding a certain threshold are pushed into both + * xid and size based queues. They are also registered in the hash table. + * + * To ensure that backend and discard worker don't register the same request + * in the hash table, we always register the request with full_xid and the + * start pointer for the transaction in the hash table as key. Backends + * always remember the value of start pointer, but discard worker doesn't know + * the actual start value in case transaction's undo spans across multiple + * logs. The reason for the same is that discard worker might encounter the + * log which has overflowed undo records of the transaction first. In such + * cases, we need to compute the actual start position. The first record of a + * transaction in each undo log contains a reference to the first record of + * this transaction in the previous log. By following the previous log chain + * of this transaction, we find the initial location which is used to register + * the request. + * + * To process the request, we get the request from one of the queues, search + * it in hash table and mark it as in-progress and then remove from the + * respective queue. Once we process all the actions, the request is removed + * from the hash table. If the worker found the request in the queue, but + * the request is not present in hash table or is marked as in-progress, then + * it can ignore such a request (and remove it from that queue) as it must + * have been already processed or is being processed. + * + * Also note that, if the work queues are full, then we put backpressure on + * backends to complete the requests by themselves. + *------------------------------------------------------------------------- + */ + +#include "postgres.h" +#include "miscadmin.h" + +#include "access/genam.h" +#include "access/heapam.h" +#include "access/transam.h" +#include "access/undorequest.h" +#include "access/xact.h" +#include "catalog/indexing.h" +#include "catalog/pg_database.h" +#include "lib/binaryheap.h" +#include "storage/bufmgr.h" +#include "storage/shmem.h" +#include "storage/procarray.h" +#include "utils/fmgroids.h" +#include "access/xlog.h" +#include "storage/proc.h" + +#define MAX_UNDO_WORK_QUEUES 3 +#define UNDO_PEEK_DEPTH 10 +#define UNDO_FAILURE_RETRY_DELAY_MS 10000 + +int rollback_overflow_size = 64; +int pending_undo_queue_size = 1024; + +/* Each worker queue is a binary heap. */ +typedef struct +{ + binaryheap *bh; + union + { + UndoXidQueue *xid_elems; + UndoSizeQueue *size_elems; + UndoErrorQueue *error_elems; + } q_choice; +} UndoWorkerQueue; + +/* This is the hash table to store all the rollabck requests. */ +static HTAB *RollbackHT; +static UndoWorkerQueue UndoWorkerQueues[MAX_UNDO_WORK_QUEUES]; + +static uint32 cur_undo_queue = 0; + +/* Different operations for XID queue */ +#define InitXidQueue(bh, elems) \ +( \ + UndoWorkerQueues[XID_QUEUE].bh = bh, \ + UndoWorkerQueues[XID_QUEUE].q_choice.xid_elems = elems \ +) + +#define XidQueueIsEmpty() \ + (binaryheap_empty(UndoWorkerQueues[XID_QUEUE].bh)) + +#define GetXidQueueSize() \ + (binaryheap_cur_size(UndoWorkerQueues[XID_QUEUE].bh)) + +#define GetXidQueueElem(elem) \ + (UndoWorkerQueues[XID_QUEUE].q_choice.xid_elems[elem]) + +#define GetXidQueueTopElem() \ +( \ + AssertMacro(!binaryheap_empty(UndoWorkerQueues[XID_QUEUE].bh)), \ + DatumGetPointer(binaryheap_first(UndoWorkerQueues[XID_QUEUE].bh)) \ +) + +#define GetXidQueueNthElem(n) \ +( \ + AssertMacro(!XidQueueIsEmpty()), \ + DatumGetPointer(binaryheap_nth(UndoWorkerQueues[XID_QUEUE].bh, n)) \ +) + +#define SetXidQueueElem(elem, e_dbid, e_full_xid, e_start_urec_ptr) \ +( \ + GetXidQueueElem(elem).dbid = e_dbid, \ + GetXidQueueElem(elem).full_xid = e_full_xid, \ + GetXidQueueElem(elem).start_urec_ptr = e_start_urec_ptr \ +) + +/* Different operations for SIZE queue */ +#define InitSizeQueue(bh, elems) \ +( \ + UndoWorkerQueues[SIZE_QUEUE].bh = bh, \ + UndoWorkerQueues[SIZE_QUEUE].q_choice.size_elems = elems \ +) + +#define SizeQueueIsEmpty() \ + (binaryheap_empty(UndoWorkerQueues[SIZE_QUEUE].bh)) + +#define GetSizeQueueSize() \ + (binaryheap_cur_size(UndoWorkerQueues[SIZE_QUEUE].bh)) + +#define GetSizeQueueElem(elem) \ + (UndoWorkerQueues[SIZE_QUEUE].q_choice.size_elems[elem]) + +#define GetSizeQueueTopElem() \ +( \ + AssertMacro(!SizeQueueIsEmpty()), \ + DatumGetPointer(binaryheap_first(UndoWorkerQueues[SIZE_QUEUE].bh)) \ +) + +#define GetSizeQueueNthElem(n) \ +( \ + AssertMacro(!SizeQueueIsEmpty()), \ + DatumGetPointer(binaryheap_nth(UndoWorkerQueues[SIZE_QUEUE].bh, n)) \ +) + +#define SetSizeQueueElem(elem, e_dbid, e_full_xid, e_size, e_start_urec_ptr) \ +( \ + GetSizeQueueElem(elem).dbid = e_dbid, \ + GetSizeQueueElem(elem).full_xid = e_full_xid, \ + GetSizeQueueElem(elem).request_size = e_size, \ + GetSizeQueueElem(elem).start_urec_ptr = e_start_urec_ptr \ +) + +/* Different operations for Error queue */ +#define InitErrorQueue(bh, elems) \ +( \ + UndoWorkerQueues[ERROR_QUEUE].bh = bh, \ + UndoWorkerQueues[ERROR_QUEUE].q_choice.error_elems = elems \ +) + +#define ErrorQueueIsEmpty() \ + (binaryheap_empty(UndoWorkerQueues[ERROR_QUEUE].bh)) + +#define GetErrorQueueSize() \ + (binaryheap_cur_size(UndoWorkerQueues[ERROR_QUEUE].bh)) + +#define GetErrorQueueElem(elem) \ + (UndoWorkerQueues[ERROR_QUEUE].q_choice.error_elems[elem]) + +#define GetErrorQueueTopElem() \ +( \ + AssertMacro(!binaryheap_empty(UndoWorkerQueues[ERROR_QUEUE].bh)), \ + DatumGetPointer(binaryheap_first(UndoWorkerQueues[ERROR_QUEUE].bh)) \ +) + +#define GetErrorQueueNthElem(n) \ +( \ + AssertMacro(!ErrorQueueIsEmpty()), \ + DatumGetPointer(binaryheap_nth(UndoWorkerQueues[ERROR_QUEUE].bh, n)) \ +) + +#define SetErrorQueueElem(elem, e_dbid, e_full_xid, e_start_urec_ptr, e_retry_at, e_occurred_at) \ +( \ + GetErrorQueueElem(elem).dbid = e_dbid, \ + GetErrorQueueElem(elem).full_xid = e_full_xid, \ + GetErrorQueueElem(elem).start_urec_ptr = e_start_urec_ptr, \ + GetErrorQueueElem(elem).next_retry_at = e_retry_at, \ + GetErrorQueueElem(elem).err_occurred_at = e_occurred_at \ +) + +/* + * Binary heap comparison function to compare the age of transactions. + */ +static int +undo_age_comparator(Datum a, Datum b, void *arg) +{ + UndoXidQueue *xidQueueElem1 = (UndoXidQueue *) DatumGetPointer(a); + UndoXidQueue *xidQueueElem2 = (UndoXidQueue *) DatumGetPointer(b); + + if (FullTransactionIdPrecedes(xidQueueElem1->full_xid, + xidQueueElem2->full_xid)) + return 1; + else if (FullTransactionIdFollows(xidQueueElem1->full_xid, + xidQueueElem2->full_xid)) + return -1; + return 0; +} + +/* + * Binary heap comparison function to compare the size of transactions. + */ +static int +undo_size_comparator(Datum a, Datum b, void *arg) +{ + UndoSizeQueue *sizeQueueElem1 = (UndoSizeQueue *) DatumGetPointer(a); + UndoSizeQueue *sizeQueueElem2 = (UndoSizeQueue *) DatumGetPointer(b); + + if (sizeQueueElem1->request_size > sizeQueueElem2->request_size) + return 1; + else if (sizeQueueElem1->request_size < sizeQueueElem2->request_size) + return -1; + return 0; +} + +/* + * Binary heap comparison function to compare the time at which an error + * occurred for transactions. + * + * The error queue is sorted by next_retry_at and err_occurred_at. Currently, + * the next_retry_at has some constant delay time (see PushErrorQueueElem), so + * it doesn't make much sense to sort by both values. However, in future, if + * we have some different algorithm for next_retry_at, then it will work + * seamlessly. + */ +static int +undo_err_time_comparator(Datum a, Datum b, void *arg) +{ + UndoErrorQueue *errQueueElem1 = (UndoErrorQueue *) DatumGetPointer(a); + UndoErrorQueue *errQueueElem2 = (UndoErrorQueue *) DatumGetPointer(b); + + if (errQueueElem1->next_retry_at < errQueueElem2->next_retry_at) + return 1; + else if (errQueueElem1->next_retry_at > errQueueElem2->next_retry_at) + return -1; + if (errQueueElem1->err_occurred_at < errQueueElem2->err_occurred_at) + return 1; + else if (errQueueElem1->err_occurred_at > errQueueElem2->err_occurred_at) + return -1; + return 0; +} + +/* Returns the size of xid based queue. */ +static int +UndoXidQueueElemsShmSize(void) +{ + return mul_size(pending_undo_queue_size, sizeof(UndoXidQueue)); +} + +/* Returns the size of rollback request size based queue. */ +static int +UndoSizeQueueElemsShmSize(void) +{ + return mul_size(pending_undo_queue_size, sizeof(UndoSizeQueue)); +} + +/* Returns the size of error queue. */ +static int +UndoErrorQueueElemsShmSize(void) +{ + return mul_size(pending_undo_queue_size, sizeof(UndoErrorQueue)); +} + +/* Returns the size of rollback hash table. */ +int +UndoRollbackHashTableSize() +{ + /* + * The rollback hash table is used to avoid duplicate undo requests by + * backends and discard worker. The table must be able to accomodate all + * active undo requests. The undo requests must appear in both xid and + * size requests queues or neither. In same transaction, there can be two + * requests one for logged relations and another for unlogged relations. + * So, the rollback hash table size should be equal to two request queues, + * an error queue (currently this is same as request queue) and max + * backends. This will ensure that it won't get filled. + */ + return ((2 * pending_undo_queue_size) + pending_undo_queue_size + + MaxBackends); +} + +/* Get the first free element of xid based request array. */ +static int +UndoXidQueueGetFreeElem(void) +{ + int i; + + for (i = 0; i < pending_undo_queue_size; i++) + { + if (FullTransactionIdEquals(GetXidQueueElem(i).full_xid, + InvalidFullTransactionId)) + return i; + } + + /* we should never call this function when the request queue is full. */ + Assert(false); + + /* silence compiler. */ + return -1; +} + +/* Push an element in the xid based request queue. */ +static void +PushXidQueueElem(UndoRequestInfo * urinfo) +{ + int elem = UndoXidQueueGetFreeElem(); + + SetXidQueueElem(elem, urinfo->dbid, urinfo->full_xid, + urinfo->start_urec_ptr); + + binaryheap_add(UndoWorkerQueues[XID_QUEUE].bh, + PointerGetDatum(&GetXidQueueElem(elem))); +} + +/* Pop nth element from the xid based request queue. */ +static UndoXidQueue * +PopXidQueueNthElem(int n) +{ + Datum elem; + + Assert(!XidQueueIsEmpty()); + elem = binaryheap_remove_nth(UndoWorkerQueues[XID_QUEUE].bh, n); + + return (UndoXidQueue *) (DatumGetPointer(elem)); +} + +/* Get the first free element of size based request array. */ +static int +UndoSizeQueueGetFreeElem(void) +{ + int i; + + for (i = 0; i < pending_undo_queue_size; i++) + { + if (FullTransactionIdEquals(GetSizeQueueElem(i).full_xid, + InvalidFullTransactionId)) + return i; + } + + /* we should never call this function when the request queue is full. */ + Assert(false); + + /* silence compiler. */ + return -1; +} + +/* + * Traverse the queue and remove dangling entries, if any. The queue + * entry is considered dangling if the hash table doesn't contain the + * corresponding entry. + */ +static int +RemoveOldElemsFromXidQueue() +{ + int nCleaned = 0; + int i = 0; + + Assert(LWLockHeldByMeInMode(RollbackRequestLock, LW_EXCLUSIVE)); + + while (i < GetXidQueueSize()) + { + RollbackHashEntry *rh; + RollbackHashKey hkey; + UndoXidQueue *elem = (UndoXidQueue *) GetXidQueueNthElem(i); + + hkey.full_xid = elem->full_xid; + hkey.start_urec_ptr = elem->start_urec_ptr; + rh = (RollbackHashEntry *) hash_search(RollbackHT, + (void *) &hkey, + HASH_FIND, NULL); + + /* + * If some undo worker is already processing the rollback request or + * it is already processed, then we drop that request from the queue. + */ + if (!rh || UndoRequestIsInProgress(rh)) + { + elem->dbid = InvalidOid; + elem->full_xid = InvalidFullTransactionId; + nCleaned++; + binaryheap_remove_nth_unordered(UndoWorkerQueues[XID_QUEUE].bh, i); + + continue; + } + + /* + * The request that is present in any queue must be a valid request + * and its status must be in_queue. + */ + Assert(UndoRequestIsValid(rh)); + Assert(UndoRequestIsInQueue(rh)); + + i++; + } + + binaryheap_build(UndoWorkerQueues[XID_QUEUE].bh); + + return nCleaned; +} + +/* Push an element in the size based request queue */ +static void +PushSizeQueueElem(UndoRequestInfo * urinfo) +{ + int elem = UndoSizeQueueGetFreeElem(); + + SetSizeQueueElem(elem, urinfo->dbid, urinfo->full_xid, + urinfo->request_size, urinfo->start_urec_ptr); + + binaryheap_add(UndoWorkerQueues[SIZE_QUEUE].bh, + PointerGetDatum(&GetSizeQueueElem(elem))); +} + +/* Pop nth element from the size based request queue */ +static UndoSizeQueue * +PopSizeQueueNthElem(int n) +{ + Datum elem; + + Assert(!binaryheap_empty(UndoWorkerQueues[SIZE_QUEUE].bh)); + elem = binaryheap_remove_nth(UndoWorkerQueues[SIZE_QUEUE].bh, n); + + return (UndoSizeQueue *) DatumGetPointer(elem); +} + +/* + * Traverse the queue and remove dangling entries, if any. The queue + * entry is considered dangling if the hash table doesn't contain the + * corresponding entry. + */ +static int +RemoveOldElemsFromSizeQueue() +{ + int nCleaned = 0; + int i = 0; + + Assert(LWLockHeldByMeInMode(RollbackRequestLock, LW_EXCLUSIVE)); + + while (i < GetSizeQueueSize()) + { + RollbackHashEntry *rh; + RollbackHashKey hkey; + UndoSizeQueue *elem = (UndoSizeQueue *) GetSizeQueueNthElem(i); + + hkey.full_xid = elem->full_xid; + hkey.start_urec_ptr = elem->start_urec_ptr; + rh = (RollbackHashEntry *) hash_search(RollbackHT, + (void *) &hkey, + HASH_FIND, NULL); + + /* + * If some undo worker is already processing the rollback request or + * it is already processed, then we drop that request from the queue. + */ + if (!rh || UndoRequestIsInProgress(rh)) + { + elem->dbid = InvalidOid; + elem->full_xid = InvalidFullTransactionId; + elem->request_size = 0; + binaryheap_remove_nth_unordered(UndoWorkerQueues[SIZE_QUEUE].bh, i); + nCleaned++; + continue; + } + + /* + * The request that is present in any queue must be a valid request + * and its status must be in_queue. + */ + Assert(UndoRequestIsValid(rh)); + Assert(UndoRequestIsInQueue(rh)); + + i++; + } + + binaryheap_build(UndoWorkerQueues[SIZE_QUEUE].bh); + + return nCleaned; +} + +/* Get the first free element of error time based request array. */ +static int +UndoErrorQueueGetFreeElem(void) +{ + int i; + + for (i = 0; i < pending_undo_queue_size; i++) + { + if (FullTransactionIdEquals(GetErrorQueueElem(i).full_xid, + InvalidFullTransactionId)) + return i; + } + + /* we should never call this function when the request queue is full. */ + Assert(false); + + /* silence compiler. */ + return -1; +} + +/* Push an element in the error time based request queue */ +static void +PushErrorQueueElem(volatile UndoRequestInfo *urinfo) +{ + int elem = UndoErrorQueueGetFreeElem(); + TimestampTz now = GetCurrentTimestamp(); + TimestampTz next_retry; + + /* + * We want to retry this error request after some constant amount of time, + * rather than retrying immediately, otherwise, in some cases (ex. when + * all the pending requests are failed requests) worker will keep retrying + * such errors constantly. + * + * In future, we might want some more sophisticated back-off algorithm + * to delay the execution of such requests. + */ + next_retry = TimestampTzPlusMilliseconds(now, UNDO_FAILURE_RETRY_DELAY_MS); + SetErrorQueueElem(elem, urinfo->dbid, urinfo->full_xid, + urinfo->start_urec_ptr, next_retry, now); + + binaryheap_add(UndoWorkerQueues[ERROR_QUEUE].bh, + PointerGetDatum(&GetErrorQueueElem(elem))); +} + +/* Pop nth element from the error time based request queue */ +static UndoErrorQueue * +PopErrorQueueNthElem(int n) +{ + Datum elem; + + Assert(!ErrorQueueIsEmpty()); + elem = binaryheap_remove_nth(UndoWorkerQueues[ERROR_QUEUE].bh, n); + + return (UndoErrorQueue *) (DatumGetPointer(elem)); +} + +/* + * Traverse the queue and remove dangling entries, if any. The queue + * entry is considered dangling if the hash table doesn't contain the + * corresponding entry. + */ +static int +RemoveOldElemsFromErrorQueue() +{ + int nCleaned = 0; + int i = 0; + + Assert(LWLockHeldByMeInMode(RollbackRequestLock, LW_EXCLUSIVE)); + + while (i < GetErrorQueueSize()) + { + RollbackHashEntry *rh; + RollbackHashKey hkey; + UndoErrorQueue *elem = (UndoErrorQueue *) GetErrorQueueNthElem(i); + + hkey.full_xid = elem->full_xid; + hkey.start_urec_ptr = elem->start_urec_ptr; + rh = (RollbackHashEntry *) hash_search(RollbackHT, + (void *) &hkey, + HASH_FIND, NULL); + + /* + * If some undo worker is already processing the rollback request or + * it is already processed, then we drop that request from the queue. + */ + if (!rh || UndoRequestIsInProgress(rh)) + { + elem->dbid = InvalidOid; + elem->full_xid = InvalidFullTransactionId; + elem->next_retry_at = 0; + elem->err_occurred_at = 0; + binaryheap_remove_nth_unordered(UndoWorkerQueues[ERROR_QUEUE].bh, i); + nCleaned++; + continue; + } + + /* + * The request that is present in any queue must be a valid request + * and its status must be in_queue. + */ + Assert(UndoRequestIsValid(rh)); + Assert(UndoRequestIsInQueue(rh)); + + i++; + } + + binaryheap_build(UndoWorkerQueues[ERROR_QUEUE].bh); + + return nCleaned; +} + +/* + * Remove nth work item from queue and clear the array element as well from + * the corresponding queue. + */ +static void +RemoveRequestFromQueue(UndoWorkerQueueType type, int n) +{ + if (type == XID_QUEUE) + { + UndoXidQueue *uXidQueueElem = (UndoXidQueue *) PopXidQueueNthElem(n); + + Assert(FullTransactionIdIsValid(uXidQueueElem->full_xid)); + uXidQueueElem->dbid = InvalidOid; + uXidQueueElem->full_xid = InvalidFullTransactionId; + } + else if (type == SIZE_QUEUE) + { + UndoSizeQueue *uSizeQueueElem = (UndoSizeQueue *) PopSizeQueueNthElem(n); + + Assert(FullTransactionIdIsValid(uSizeQueueElem->full_xid)); + uSizeQueueElem->dbid = InvalidOid; + uSizeQueueElem->full_xid = InvalidFullTransactionId; + uSizeQueueElem->request_size = 0; + } + else + { + UndoErrorQueue *uErrorQueueElem = (UndoErrorQueue *) PopErrorQueueNthElem(n); + + Assert(type == ERROR_QUEUE); + Assert(FullTransactionIdIsValid(uErrorQueueElem->full_xid)); + uErrorQueueElem->dbid = InvalidOid; + uErrorQueueElem->full_xid = InvalidFullTransactionId; + uErrorQueueElem->next_retry_at = 0; + uErrorQueueElem->err_occurred_at = 0; + } +} + +/* + * Returns true, if there is some valid request in the given queue, false, + * otherwise. + * + * It fills hkey with hash key corresponding to the nth element of the + * specified queue. + */ +static bool +GetRollbackHashKeyFromQueue(UndoWorkerQueueType cur_queue, int n, + RollbackHashKey *hkey) +{ + if (cur_queue == XID_QUEUE) + { + UndoXidQueue *elem; + + /* check if there is a work in the next queue */ + if (GetXidQueueSize() <= n) + return false; + + elem = (UndoXidQueue *) GetXidQueueNthElem(n); + hkey->full_xid = elem->full_xid; + hkey->start_urec_ptr = elem->start_urec_ptr; + } + else if (cur_queue == SIZE_QUEUE) + { + UndoSizeQueue *elem; + + /* check if there is a work in the next queue */ + if (GetSizeQueueSize() <= n) + return false; + + elem = (UndoSizeQueue *) GetSizeQueueNthElem(n); + hkey->full_xid = elem->full_xid; + hkey->start_urec_ptr = elem->start_urec_ptr; + } + else + { + UndoErrorQueue *elem; + + /* It must be an error queue. */ + Assert(cur_queue == ERROR_QUEUE); + + /* check if there is a work in the next queue */ + if (GetErrorQueueSize() <= n) + return false; + + elem = (UndoErrorQueue *) GetErrorQueueNthElem(n); + + /* + * If it is too early to try the error request again, then check the + * work in some other queue. + */ + if (GetCurrentTimestamp() < elem->next_retry_at) + return false; + + hkey->full_xid = elem->full_xid; + hkey->start_urec_ptr = elem->start_urec_ptr; + } + + return true; +} + +/* + * Fetch the end urec pointer for the transaction and the undo request size. + * + * end_urecptr_out - This is an INOUT parameter. If end undo pointer is + * specified, we use the same to calculate the size. Else, we calculate + * the end undo pointer and return the same. + * + * last_log_start_urec_ptr_out - This is an OUT parameter. If a transaction + * writes undo records in multiple undo logs, this is set to the start undo + * record pointer of this transaction in the last log. If the transaction + * writes undo records only in single undo log, it is set to start_urec_ptr. + * This value is used to update the rollback progress of the transaction in + * the last log. Once, we have start location in last log, the start location + * in all the previous logs can be computed. See execute_undo_actions for + * more details. + * + * XXX: We don't calculate the exact undo size. We always skip the size of + * the last undo record (if not already discarded) from the calculation. This + * optimization allows us to skip fetching an undo record for the most + * frequent cases where the end pointer and current start pointer belong to + * the same log. A simple subtraction between them gives us the size. In + * future this function can be modified if someone needs the exact undo size. + * As of now, we use this function to calculate the undo size for inserting + * in the pending undo actions in undo worker's size queue. + */ +uint64 +FindUndoEndLocationAndSize(UndoRecPtr start_urecptr, + UndoRecPtr *end_urecptr_out, + UndoRecPtr *last_log_start_urecptr_out, + FullTransactionId full_xid) +{ + UnpackedUndoRecord *uur = NULL; + UndoLogSlot *slot = NULL; + UndoRecPtr urecptr = start_urecptr; + UndoRecPtr end_urecptr = InvalidUndoRecPtr; + UndoRecPtr last_log_start_urecptr = InvalidUndoRecPtr; + uint64 sz = 0; + UndoLogCategory category; + + Assert(urecptr != InvalidUndoRecPtr); + + while (true) + { + UndoRecPtr next_urecptr = InvalidUndoRecPtr; + UndoLogOffset next_insert; + UndoRecordFetchContext context; + + if (*end_urecptr_out != InvalidUndoRecPtr) + { + /* + * Check whether end pointer and the current pointer belong to + * same log. In that case, we can get the size easily. + */ + if (UndoRecPtrGetLogNo(urecptr) == UndoRecPtrGetLogNo(*end_urecptr_out)) + { + last_log_start_urecptr = urecptr; + sz += (*end_urecptr_out - urecptr); + break; + } + } + + /* + * Fetch the log and undo record corresponding to the current undo + * pointer. + */ + if ((slot == NULL) || (UndoRecPtrGetLogNo(urecptr) != slot->logno)) + slot = UndoLogGetSlot(UndoRecPtrGetLogNo(urecptr), false); + + Assert(slot != NULL); + category = slot->meta.category; + + next_insert = UndoLogGetNextInsertPtr(slot->logno); + + /* The corresponding log must be ahead urecptr. */ + Assert(MakeUndoRecPtr(slot->logno, slot->meta.unlogged.insert) >= urecptr); + + /* Fetch the undo record. */ + BeginUndoFetch(&context); + uur = UndoFetchRecord(&context, urecptr); + FinishUndoFetch(&context); + + /* + * If the corresponding undo record got rolled back and discarded as + * well, we return from here. + */ + if (uur == NULL) + break; + + /* The undo must belongs to a same transaction. */ + Assert(FullTransactionIdEquals(full_xid, uur->uur_fxid)); + + /* + * Since this is the first undo record of this transaction in this + * log, this must include the transaction header. + */ + Assert(uur->uur_info & UREC_INFO_TRANSACTION); + + /* + * Case 1: Check whether any undo records have been applied from this + * log. Else, we've to find the undo location till where the undo + * actions have been applied. + */ + if (!IsXactApplyProgressNotStarted(uur->uur_txn->urec_progress)) + { + /* + * If all the undo records in this log corresponding to this + * transaction, has been applied, we return from here. + */ + if (IsXactApplyProgressCompleted(uur->uur_txn->urec_progress)) + break; + + /* + * Find the first undo record of uur_progress block number. We'll + * set end_urec_ptr to this undo record. + */ + end_urecptr = UndoBlockGetFirstUndoRecord(uur->uur_txn->urec_progress, + urecptr, category); + + /* + * Since rollbacks from this undo log are in-progress, all undo + * records from subsequent undo logs must have been applied. Hence, + * this is the last log. So, we set last_log_start_urecptr as the + * start undo record pointer of this transaction from current log. + */ + last_log_start_urecptr = urecptr; + sz += (end_urecptr - urecptr); + break; + } + + next_urecptr = uur->uur_txn->urec_next; + + /* + * Case 2: If this is the last transaction in the log then calculate + * the latest urec pointer using next insert location of the undo log. + * + * Even if some new undo got inserted after we have fetched this + * transactions undo record, still the next_insert location will give + * us the right point to compute end_urecptr. + */ + if (!UndoRecPtrIsValid(next_urecptr)) + { + last_log_start_urecptr = urecptr; + end_urecptr = UndoGetPrevUndoRecptr(next_insert, InvalidBuffer, category); + sz += (end_urecptr - urecptr); + Assert(UndoRecPtrIsValid(end_urecptr)); + break; + } + + /* + * Case 3: The transaction ended in the same undo log, but this is not + * the last transaction. + */ + if (UndoRecPtrGetLogNo(next_urecptr) == slot->logno) + { + last_log_start_urecptr = urecptr; + end_urecptr = + UndoGetPrevUndoRecptr(next_urecptr, InvalidBuffer, category); + sz += (end_urecptr - urecptr); + Assert(UndoRecPtrIsValid(end_urecptr)); + break; + } + + /* + * Case 4: If transaction is overflowed to a different undolog and + * it's already discarded. It means that the undo actions for this + * transaction which are in the next log are already executed. + */ + if (UndoRecPtrIsDiscarded(next_urecptr)) + { + UndoLogOffset next_insert; + + next_insert = UndoLogGetNextInsertPtr(slot->logno); + Assert(UndoRecPtrIsValid(next_insert)); + + last_log_start_urecptr = urecptr; + end_urecptr = UndoGetPrevUndoRecptr(next_insert, InvalidBuffer, category); + sz += (next_insert - urecptr); + Assert(UndoRecPtrIsValid(end_urecptr)); + break; + } + + /* + * Case 5: The transaction is overflowed to a different log, so + * restart the processing from then next log but before that consider + * this log for request size computation. + */ + { + UndoLogOffset next_insert; + + next_insert = UndoLogGetNextInsertPtr(slot->logno); + Assert(UndoRecPtrIsValid(next_insert)); + + last_log_start_urecptr = urecptr; + end_urecptr = UndoGetPrevUndoRecptr(next_insert, InvalidBuffer, category); + sz += (next_insert - urecptr); + + UndoRecordRelease(uur); + uur = NULL; + } + + /* Follow the undo chain */ + urecptr = next_urecptr; + } + + if (uur != NULL) + UndoRecordRelease(uur); + + if (end_urecptr_out && (*end_urecptr_out == InvalidUndoRecPtr)) + *end_urecptr_out = end_urecptr; + if (last_log_start_urecptr_out && + (*last_log_start_urecptr_out == InvalidUndoRecPtr)) + *last_log_start_urecptr_out = last_log_start_urecptr; + + return sz; +} + +/* + * Returns true, if we can push the rollback request to undo wrokers, false, + * otherwise. + */ +static bool +CanPushReqToUndoWorker(UndoRecPtr start_urec_ptr, UndoRecPtr end_urec_ptr, + uint64 req_size) +{ + /* + * This must be called after acquring RollbackRequestLock as we will check + * the binary heaps which can change. + */ + Assert(LWLockHeldByMeInMode(RollbackRequestLock, LW_EXCLUSIVE)); + + /* + * We normally push the rollback request to undo workers if the size of + * same is above a certain threshold. + */ + if (req_size >= rollback_overflow_size * 1024 * 1024) + { + if (GetXidQueueSize() >= pending_undo_queue_size || + GetSizeQueueSize() >= pending_undo_queue_size) + { + /* + * If one of the queues is full traverse both the queues and + * remove dangling entries, if any. The queue entry is considered + * dangling if the hash table doesn't contain the corresponding + * entry. It can happen due to two reasons (a) we have processed + * the entry from one of the queues, but not from the other. (b) + * the corresponding database has been dropped due to which we + * have removed the entries from hash table, but not from the + * queues. This is just a lazy cleanup, if we want we can remove + * the entries from the queues when we detect that the database is + * dropped and remove the corresponding entries from hash table. + */ + if (GetXidQueueSize() >= pending_undo_queue_size) + RemoveOldElemsFromXidQueue(); + if (GetSizeQueueSize() >= pending_undo_queue_size) + RemoveOldElemsFromSizeQueue(); + } + + if ((GetXidQueueSize() < pending_undo_queue_size)) + { + Assert(GetSizeQueueSize() < pending_undo_queue_size); + + /* + * XXX - Here, we should return true once we have background + * worker facility. + */ + return false; + } + } + + return false; +} + +/* + * To return the size of the request queues and hash-table for rollbacks. + */ +int +PendingUndoShmemSize(void) +{ + Size size; + + size = hash_estimate_size(UndoRollbackHashTableSize(), sizeof(RollbackHashEntry)); + size = add_size(size, mul_size(MAX_UNDO_WORK_QUEUES, + binaryheap_shmem_size(pending_undo_queue_size))); + size = add_size(size, UndoXidQueueElemsShmSize()); + size = add_size(size, UndoSizeQueueElemsShmSize()); + size = add_size(size, UndoErrorQueueElemsShmSize()); + + return size; +} + +/* + * Initialize the hash-table and priority heap based queues for rollback + * requests in shared memory. + */ +void +PendingUndoShmemInit(void) +{ + HASHCTL info; + bool foundXidQueue = false; + bool foundSizeQueue = false; + bool foundErrorQueue = false; + binaryheap *bh; + UndoXidQueue *xid_elems; + UndoSizeQueue *size_elems; + UndoErrorQueue *error_elems; + + MemSet(&info, 0, sizeof(info)); + + info.keysize = sizeof(TransactionId) + sizeof(UndoRecPtr); + info.entrysize = sizeof(RollbackHashEntry); + info.hash = tag_hash; + + RollbackHT = ShmemInitHash("Undo Actions Lookup Table", + UndoRollbackHashTableSize(), + UndoRollbackHashTableSize(), &info, + HASH_ELEM | HASH_FUNCTION | HASH_FIXED_SIZE); + + bh = binaryheap_allocate_shm("Undo Xid Binary Heap", + pending_undo_queue_size, + undo_age_comparator, + NULL); + + xid_elems = (UndoXidQueue *) ShmemInitStruct("Undo Xid Queue Elements", + UndoXidQueueElemsShmSize(), + &foundXidQueue); + + Assert(foundXidQueue || !IsUnderPostmaster); + + if (!IsUnderPostmaster) + memset(xid_elems, 0, sizeof(UndoXidQueue)); + + InitXidQueue(bh, xid_elems); + + bh = binaryheap_allocate_shm("Undo Size Binary Heap", + pending_undo_queue_size, + undo_size_comparator, + NULL); + size_elems = (UndoSizeQueue *) ShmemInitStruct("Undo Size Queue Elements", + UndoSizeQueueElemsShmSize(), + &foundSizeQueue); + Assert(foundSizeQueue || !IsUnderPostmaster); + + if (!IsUnderPostmaster) + memset(size_elems, 0, sizeof(UndoSizeQueue)); + + InitSizeQueue(bh, size_elems); + + bh = binaryheap_allocate_shm("Undo Error Binary Heap", + pending_undo_queue_size, + undo_err_time_comparator, + NULL); + + error_elems = (UndoErrorQueue *) ShmemInitStruct("Undo Error Queue Elements", + UndoErrorQueueElemsShmSize(), + &foundErrorQueue); + Assert(foundErrorQueue || !IsUnderPostmaster); + + if (!IsUnderPostmaster) + memset(error_elems, 0, sizeof(UndoSizeQueue)); + + InitErrorQueue(bh, error_elems); +} + +/* + * Returns true, if there is no pending undo apply work, false, otherwise. + */ +bool +UndoWorkerQueuesEmpty(void) +{ + if (XidQueueIsEmpty() && SizeQueueIsEmpty()) + return true; + + return false; +} + +/* Insert the request in both xid and size based queues. */ +void +InsertRequestIntoUndoQueues(UndoRequestInfo * urinfo) +{ + /* + * This must be called after acquring RollbackRequestLock as we will + * insert into the binary heaps which can change. + */ + Assert(LWLockHeldByMeInMode(RollbackRequestLock, LW_EXCLUSIVE)); + PushXidQueueElem(urinfo); + PushSizeQueueElem(urinfo); + + elog(DEBUG1, "Undo action pushed Xid: " UINT64_FORMAT ", Size: " UINT64_FORMAT ", " + "Start: " UndoRecPtrFormat ", End: " UndoRecPtrFormat "", + U64FromFullTransactionId(urinfo->full_xid), urinfo->request_size, + urinfo->start_urec_ptr, urinfo->end_urec_ptr); +} + +/* Insert the request into an error queue. */ +bool +InsertRequestIntoErrorUndoQueue(volatile UndoRequestInfo * urinfo) +{ + RollbackHashEntry *rh; + + LWLockAcquire(RollbackRequestLock, LW_EXCLUSIVE); + + /* We can't insert into an error queue if it is already full. */ + if (GetErrorQueueSize() >= pending_undo_queue_size) + { + int num_removed = 0; + + /* Try to remove few elements */ + num_removed = RemoveOldElemsFromErrorQueue(); + + if (num_removed == 0) + { + LWLockRelease(RollbackRequestLock); + return false; + } + } + + /* + * Mark the undo request in hash table as UNDO_REQUEST_INQUEUE so that undo + * launcher or other undo worker can process this request. + */ + rh = (RollbackHashEntry *) hash_search(RollbackHT, (void *) &urinfo->full_xid, + HASH_FIND, NULL); + rh->status = UNDO_REQUEST_INQUEUE; + + /* Insert the request into error queue for processing it later. */ + PushErrorQueueElem(urinfo); + LWLockRelease(RollbackRequestLock); + + elog(DEBUG1, "Undo action pushed(error) Xid: " UINT64_FORMAT ", Size: " UINT64_FORMAT ", " + "Start: " UndoRecPtrFormat ", End: " UndoRecPtrFormat "", + U64FromFullTransactionId(urinfo->full_xid), urinfo->request_size, + urinfo->start_urec_ptr, urinfo->end_urec_ptr); + + return true; +} + +/* + * Set the undo worker queue from which the undo worker should start looking + * for work. + */ +void +SetUndoWorkerQueueStart(UndoWorkerQueueType undo_worker_queue) +{ + cur_undo_queue = undo_worker_queue; +} + +/* + * Get the next set of pending rollback request for undo worker. + * + * allow_peek - if true, peeks a few element from each queue to check whether + * any request matches current dbid. + * remove_from_queue - if true, picks an element from the queue whose dbid + * matches current dbid and remove it from the queue before returning the same + * to caller. + * urinfo - this is an OUT parameter that returns the details of undo request + * whose undo action is still pending. + * in_other_db_out - this is an OUT parameter. If we've not found any work + * for current database, but there is work for some other database, we set + * this parameter as true. + */ +bool +UndoGetWork(bool allow_peek, bool remove_from_queue, UndoRequestInfo *urinfo, + bool *in_other_db_out) +{ + int i; + bool found_work = false; + bool in_other_db = false; + + /* Reset the undo request info */ + ResetUndoRequestInfo(urinfo); + + /* Search the queues under lock as they can be modified concurrently. */ + LWLockAcquire(RollbackRequestLock, LW_EXCLUSIVE); + + /* Here, we check each of the work queues in a round-robin way. */ + for (i = 0; i < MAX_UNDO_WORK_QUEUES; i++) + { + RollbackHashKey hkey; + RollbackHashEntry *rh; + int cur_queue = (int) (cur_undo_queue % MAX_UNDO_WORK_QUEUES); + + if (!GetRollbackHashKeyFromQueue(cur_queue, 0, &hkey)) + { + cur_undo_queue++; + continue; + } + + rh = (RollbackHashEntry *) hash_search(RollbackHT, + (void *) &hkey, + HASH_FIND, NULL); + + /* + * If some undo worker is already processing the rollback request or + * it is already processed, then we drop that request from the queue + * and fetch the next entry from the queue. + */ + if (!rh || UndoRequestIsInProgress(rh)) + { + RemoveRequestFromQueue(cur_queue, 0); + cur_undo_queue++; + continue; + } + + /* + * The request that is present in any queue must be a valid request + * and its status must be in_queue. + */ + Assert(UndoRequestIsValid(rh)); + Assert(UndoRequestIsInQueue(rh)); + + found_work = true; + + /* + * We've found a work for some database. If we don't want to remove + * the request, we return from here and spawn a worker process to + * apply the same. + */ + if (!remove_from_queue) + { + bool exists; + + StartTransactionCommand(); + exists = dbid_exists(rh->dbid); + CommitTransactionCommand(); + + /* + * If the database doesn't exist, just remove the request since we + * no longer need to apply the undo actions. + */ + if (!exists) + { + RemoveRequestFromQueue(cur_queue, 0); + RollbackHTRemoveEntry(rh->full_xid, rh->start_urec_ptr, true); + cur_undo_queue++; + continue; + } + + /* set the undo request info to process */ + SetUndoRequestInfoFromRHEntry(urinfo, rh, cur_queue); + + cur_undo_queue++; + LWLockRelease(RollbackRequestLock); + return true; + } + + /* + * The worker can perform this request if it is either not connected + * to any database or the request belongs to the same database to + * which it is connected. + */ + if ((MyDatabaseId == InvalidOid) || + (MyDatabaseId != InvalidOid && MyDatabaseId == rh->dbid)) + { + /* found a work for current database */ + if (in_other_db_out) + *in_other_db_out = false; + + /* + * Mark the undo request in hash table as in_progress so that + * other undo worker doesn't pick the same entry for rollback. + */ + rh->status = UNDO_REQUEST_INPROGRESS; + + /* set the undo request info to process */ + SetUndoRequestInfoFromRHEntry(urinfo, rh, cur_queue); + + /* + * Remove the request from queue so that other undo worker doesn't + * process the same entry. + */ + RemoveRequestFromQueue(cur_queue, 0); + + cur_undo_queue++; + LWLockRelease(RollbackRequestLock); + return true; + } + else + in_other_db = true; + + cur_undo_queue++; + } + + /* + * Iff a worker would need to switch databases in less than + * undo_worker_quantum ms after starting, it peeks a few entries deep into + * each queue to see whether there's work for that database. This ensures + * that one worker doesn't have to restart quickly to switch databases. + */ + if (allow_peek) + { + int depth, + cur_queue; + RollbackHashKey hkey; + RollbackHashEntry *rh; + + /* + * We shouldn't have come here if we've found a work above for our + * database. + */ + Assert(!found_work || in_other_db); + + for (depth = 0; depth < UNDO_PEEK_DEPTH; depth++) + { + for (cur_queue = 0; cur_queue < MAX_UNDO_WORK_QUEUES; cur_queue++) + { + if (!GetRollbackHashKeyFromQueue(cur_queue, depth, &hkey)) + continue; + + rh = (RollbackHashEntry *) hash_search(RollbackHT, + (void *) &hkey, + HASH_FIND, NULL); + + /* + * If some undo worker is already processing the rollback + * request or it is already processed, then fetch the next + * entry from the queue. + */ + if (!rh || UndoRequestIsInProgress(rh)) + continue; + + /* + * The request that is present in any queue must be a valid request + * and its status must be in_queue. + */ + Assert(UndoRequestIsValid(rh)); + Assert(UndoRequestIsInQueue(rh)); + + found_work = true; + + /* + * The worker can perform this request if it is either not + * connected to any database or the request belongs to the + * same database to which it is connected. + */ + if ((MyDatabaseId == InvalidOid) || + (MyDatabaseId != InvalidOid && MyDatabaseId == rh->dbid)) + { + /* found a work for current database */ + if (in_other_db_out) + *in_other_db_out = false; + + /* + * Mark the undo request in hash table as in_progress so + * that other undo worker doesn't pick the same entry for + * rollback. + */ + rh->status = UNDO_REQUEST_INPROGRESS; + + /* set the undo request info to process */ + SetUndoRequestInfoFromRHEntry(urinfo, rh, cur_queue); + + /* + * Remove the request from queue so that other undo worker + * doesn't process the same entry. + */ + RemoveRequestFromQueue(cur_queue, depth); + LWLockRelease(RollbackRequestLock); + return true; + } + else + in_other_db = true; + } + } + } + + LWLockRelease(RollbackRequestLock); + + if (in_other_db_out) + *in_other_db_out = in_other_db; + + return found_work; +} + +/* + * This function registers the rollback requests. + * + * Returns true, if the request is registered and will be processed by undo + * worker at some later point of time, false, otherwise in which case caller + * can process the undo request by itself. + * + * The caller may execute undo actions itself if the request is not already + * present in rollback hash table and can't be pushed to pending undo request + * queues. The two reasons why request can't be pushed are (a) the size of + * request is smaller than a threshold and the request is not from discard + * worker, (b) the undo request queues are full. + * + * It is not advisable to apply the undo actions of a very large transaction + * in the foreground as that can lead to a delay in retruning the control back + * to user after abort. + */ +bool +RegisterUndoRequest(UndoRecPtr end_urec_ptr, UndoRecPtr start_urec_ptr, + Oid dbid, FullTransactionId full_xid) +{ + bool found = false; + bool can_push; + bool pushed = false; + RollbackHashEntry *rh; + uint64 req_size = 0; + UndoRecPtr last_log_start_urec_ptr = InvalidUndoRecPtr; + RollbackHashKey hkey; + + Assert(UndoRecPtrIsValid(start_urec_ptr)); + Assert(dbid != InvalidOid); + + /* + * Find the rollback request size and the end_urec_ptr (in case of discard + * worker only). + */ + req_size = FindUndoEndLocationAndSize(start_urec_ptr, &end_urec_ptr, + &last_log_start_urec_ptr, full_xid); + + /* Do not push any rollback request if working in single user-mode */ + if (!IsUnderPostmaster) + return false; + + /* The transaction got rolled back. */ + if (!UndoRecPtrIsValid(end_urec_ptr)) + return false; + + LWLockAcquire(RollbackRequestLock, LW_EXCLUSIVE); + + /* + * Check whether we can push the rollback request to the undo worker. This + * must be done under lock, see CanPushReqToUndoWorker. + */ + can_push = CanPushReqToUndoWorker(start_urec_ptr, end_urec_ptr, req_size); + + hkey.full_xid = full_xid; + hkey.start_urec_ptr = start_urec_ptr; + + rh = (RollbackHashEntry *) hash_search(RollbackHT, &hkey, + HASH_ENTER_NULL, &found); + + /* + * It can only fail, if the value of pending_undo_queue_size or + * max_connections guc is reduced after restart of the server. + */ + if (rh == NULL) + { + Assert(RollbackHTIsFull()); + + ereport(PANIC, + (errcode(ERRCODE_INSUFFICIENT_RESOURCES), + errmsg("rollback hash table is full, try running with higher value of pending_undo_queue_size"))); + } + + /* We shouldn't try to add the same rollback request again. */ + if (!found) + { + rh->start_urec_ptr = start_urec_ptr; + rh->end_urec_ptr = end_urec_ptr; + rh->last_log_start_urec_ptr = last_log_start_urec_ptr; + rh->dbid = dbid; + rh->full_xid = full_xid; + + /* Increment the pending request counter. */ + ProcGlobal->xactsHavingPendingUndo++; + + if (can_push) + { + UndoRequestInfo urinfo; + + ResetUndoRequestInfo(&urinfo); + + urinfo.full_xid = rh->full_xid; + urinfo.start_urec_ptr = rh->start_urec_ptr; + urinfo.end_urec_ptr = rh->end_urec_ptr; + urinfo.last_log_start_urec_ptr = rh->last_log_start_urec_ptr; + urinfo.dbid = rh->dbid; + urinfo.request_size = req_size; + + InsertRequestIntoUndoQueues(&urinfo); + + /* + * Indicates that the request will be processed by undo + * worker. + */ + rh->status = UNDO_REQUEST_INQUEUE; + pushed = true; + } + /* + * The request can't be pushed into the undo worker queue. The + * backends will try executing by itself. + */ + else + rh->status = UNDO_REQUEST_INPROGRESS; + } + else if (!UndoRequestIsValid(rh) && can_push) + { + /* + * If we found the request which is still not in queue or not in + * progress then add it to the queue if there is a space in the queue. + */ + UndoRequestInfo urinfo; + + ResetUndoRequestInfo(&urinfo); + + urinfo.full_xid = rh->full_xid; + urinfo.start_urec_ptr = rh->start_urec_ptr; + urinfo.end_urec_ptr = rh->end_urec_ptr; + urinfo.last_log_start_urec_ptr = rh->last_log_start_urec_ptr; + urinfo.dbid = rh->dbid; + urinfo.request_size = req_size; + + InsertRequestIntoUndoQueues(&urinfo); + + /* Indicates that the request will be processed by the undo worker */ + rh->status = UNDO_REQUEST_INQUEUE; + pushed = true; + } + + LWLockRelease(RollbackRequestLock); + + return pushed; +} + +/* + * Remove the rollback request entry from the rollback hash table. + */ +void +RollbackHTRemoveEntry(FullTransactionId full_xid, UndoRecPtr start_urec_ptr, + bool lock) +{ + RollbackHashKey hkey; + + hkey.full_xid = full_xid; + hkey.start_urec_ptr = start_urec_ptr; + + if (!lock) + LWLockAcquire(RollbackRequestLock, LW_EXCLUSIVE); + + hash_search(RollbackHT, &hkey, HASH_REMOVE, NULL); + + /* Decrement the pending request counter. */ + ProcGlobal->xactsHavingPendingUndo--; + + if (!lock) + LWLockRelease(RollbackRequestLock); +} + +/* + * Mark the entry status as invalid in the rollback hash table. + */ +void +RollbackHTMarkEntryInvalid(FullTransactionId full_xid, + UndoRecPtr start_urec_ptr) +{ + RollbackHashKey hkey; + RollbackHashEntry *rh; + + hkey.full_xid = full_xid; + hkey.start_urec_ptr = start_urec_ptr; + + LWLockAcquire(RollbackRequestLock, LW_EXCLUSIVE); + + rh = (RollbackHashEntry *) hash_search(RollbackHT, &hkey, HASH_FIND, NULL); + Assert(rh != NULL); + rh->status = UNDO_REQUEST_INVALID; + + LWLockRelease(RollbackRequestLock); +} + +/* + * Returns the start undo record pointer for the last undo log in which + * transaction has spanned. This will be different from start_urec_ptr only + * when the undo for a transaction has spanned across multiple undo logs. + */ +UndoRecPtr +RollbackHTGetLastLogStartUrp(FullTransactionId full_xid, + UndoRecPtr start_urec_ptr) +{ + RollbackHashKey hkey; + RollbackHashEntry *rh; + UndoRecPtr last_log_start_urecptr; + + hkey.full_xid = full_xid; + hkey.start_urec_ptr = start_urec_ptr; + + LWLockAcquire(RollbackRequestLock, LW_EXCLUSIVE); + + rh = (RollbackHashEntry *) hash_search(RollbackHT, &hkey, HASH_FIND, NULL); + Assert(rh != NULL); + last_log_start_urecptr = rh->last_log_start_urec_ptr; + LWLockRelease(RollbackRequestLock); + + return last_log_start_urecptr; +} + +/* + * Returns true, if the rollback hash table is full, false, otherwise. + */ +bool +RollbackHTIsFull(void) +{ + bool result = false; + + LWLockAcquire(RollbackRequestLock, LW_SHARED); + + if (hash_get_num_entries(RollbackHT) >= UndoRollbackHashTableSize()) + result = true; + + LWLockRelease(RollbackRequestLock); + + return result; +} + +/* + * Get the smallest of 'xid having pending undo' and 'oldestXmin'. + */ +FullTransactionId +RollbackHTGetOldestFullXid(FullTransactionId oldestXmin) +{ + RollbackHashEntry *rh; + FullTransactionId oldestXid = oldestXmin; + HASH_SEQ_STATUS status; + + /* Fetch the pending undo requests */ + LWLockAcquire(RollbackRequestLock, LW_SHARED); + + Assert(hash_get_num_entries(RollbackHT) <= UndoRollbackHashTableSize()); + hash_seq_init(&status, RollbackHT); + while (RollbackHT != NULL && + (rh = (RollbackHashEntry *) hash_seq_search(&status)) != NULL) + { + if (!FullTransactionIdIsValid(oldestXid) || + FullTransactionIdPrecedes(rh->full_xid, oldestXid)) + oldestXid = rh->full_xid; + } + + LWLockRelease(RollbackRequestLock); + + return oldestXid; +} diff --git a/src/backend/storage/lmgr/lwlocknames.txt b/src/backend/storage/lmgr/lwlocknames.txt index 4b42a1c..19e4f1f 100644 --- a/src/backend/storage/lmgr/lwlocknames.txt +++ b/src/backend/storage/lmgr/lwlocknames.txt @@ -50,3 +50,4 @@ OldSnapshotTimeMapLock 42 LogicalRepWorkerLock 43 CLogTruncationLock 44 UndoLogLock 45 +RollbackRequestLock 46 diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 498373f..884fa2a 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -296,6 +296,8 @@ InitProcGlobal(void) /* Create ProcStructLock spinlock, too */ ProcStructLock = (slock_t *) ShmemAlloc(sizeof(slock_t)); SpinLockInit(ProcStructLock); + + ProcGlobal->xactsHavingPendingUndo = 0; } /* diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index 5d9af89..ede9c51 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -1086,6 +1086,20 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, } /* + * Check whether the dbid exist or not. + */ +bool +dbid_exists(Oid dboid) +{ + bool result = false; + + Assert(IsTransactionState()); + result = (GetDatabaseTupleByOid(dboid) != NULL); + + return result; +} + +/* * Process any command-line switches and any additional GUC variable * settings passed in the startup packet. */ diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 296fb77..a7d1db5 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -32,6 +32,7 @@ #include "access/tableam.h" #include "access/transam.h" #include "access/twophase.h" +#include "access/undorequest.h" #include "access/xact.h" #include "access/xlog_internal.h" #include "catalog/namespace.h" @@ -3041,6 +3042,27 @@ static struct config_int ConfigureNamesInt[] = }, { + {"rollback_overflow_size", PGC_USERSET, RESOURCES_MEM, + gettext_noop("Rollbacks greater than this size are done lazily"), + NULL, + GUC_UNIT_MB + }, + &rollback_overflow_size, + 64, 0, MAX_KILOBYTES, + NULL, NULL, NULL + }, + + { + {"pending_undo_queue_size", PGC_POSTMASTER, RESOURCES_MEM, + gettext_noop("Sets the size of queue used to register undo requests"), + NULL, + }, + &pending_undo_queue_size, + 1024, 0, INT_MAX, + NULL, NULL, NULL + }, + + { {"old_snapshot_threshold", PGC_POSTMASTER, RESOURCES_ASYNCHRONOUS, gettext_noop("Time before a snapshot is too old to read pages changed after the snapshot was taken."), gettext_noop("A value of -1 disables this feature."), diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index cfad86c..592f6e1 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -604,6 +604,14 @@ # autovacuum, -1 means use # vacuum_cost_limit +#------------------------------------------------------------------------------ +# UNDO options +#------------------------------------------------------------------------------ + +#rollback_overflow_size = 64 # default size above which the undo + # requests are pushed to undo workers +#pending_undo_queue_size = 1024 # size of queue used to register undo + # requests #------------------------------------------------------------------------------ # CLIENT CONNECTION DEFAULTS diff --git a/src/include/access/transam.h b/src/include/access/transam.h index cc00509..01f248a 100644 --- a/src/include/access/transam.h +++ b/src/include/access/transam.h @@ -49,6 +49,7 @@ #define U64FromFullTransactionId(x) ((x).value) #define FullTransactionIdEquals(a, b) ((a).value == (b).value) #define FullTransactionIdPrecedes(a, b) ((a).value < (b).value) +#define FullTransactionIdFollows(a, b) ((a).value > (b).value) #define FullTransactionIdIsValid(x) TransactionIdIsValid(XidFromFullTransactionId(x)) #define InvalidFullTransactionId FullTransactionIdFromEpochAndXid(0, InvalidTransactionId) diff --git a/src/include/access/undoaccess.h b/src/include/access/undoaccess.h index f7cfa9f..24ea97b 100644 --- a/src/include/access/undoaccess.h +++ b/src/include/access/undoaccess.h @@ -117,5 +117,8 @@ extern void UndoLogBuffersSetLSN(UndoRecordInsertContext *context, XLogRecPtr recptr); extern UndoRecPtr UndoGetPrevUndoRecptr(UndoRecPtr urp, Buffer buffer, UndoLogCategory category); +extern UndoRecPtr UndoBlockGetFirstUndoRecord(BlockNumber blkno, + UndoRecPtr urec_ptr, + UndoLogCategory category); #endif /* UNDOINSERT_H */ diff --git a/src/include/access/undorequest.h b/src/include/access/undorequest.h new file mode 100644 index 0000000..64d89ba --- /dev/null +++ b/src/include/access/undorequest.h @@ -0,0 +1,231 @@ +/*------------------------------------------------------------------------- + * + * undorequest.h + * Exports from undo/undorequest.c. + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * + * src/include/access/undorequest.h + * + *------------------------------------------------------------------------- + */ +#ifndef _UNDOREQUEST_H +#define _UNDOREQUEST_H + +#include "access/transam.h" +#include "access/undoaccess.h" +#include "datatype/timestamp.h" +#include "utils/relcache.h" + + +/* different types of undo worker */ +typedef enum +{ + XID_QUEUE = 0, + SIZE_QUEUE = 1, + ERROR_QUEUE +} UndoWorkerQueueType; + +#define InvalidUndoWorkerQueue -1 + +extern PGDLLIMPORT int rollback_overflow_size; +extern PGDLLIMPORT int pending_undo_queue_size; + +/* + * Current status of the undo request in the hash table. + */ +typedef enum +{ + /* + * Request is present in the rollback hash table, but not present in any + * of the queues. In this state, the undo actions can't be executed. + * + * The request will be marked with this status if a) discard worker finds + * that there is no space in the undo worker queue for inserting the undo + * request, b) there is an error while backend or undo worker is + * executing undo actions and there is no space in the error queue. + * + * Later when the discard worker finds such entry and if there is a + * sufficient space in the undo worker queues, then the request will be + * added to them and the status will be changed to UNDO_REQUEST_INQUEUE. + * + * It is important to keep the request in hash table with this status + * intsead of removing it to compute the value of + * oldestXidHavingUnappliedUndo. If we don't do that, then the + * corresponding xid won't be considered for computation of + * oldestXidHavingUnappliedUndo. + */ + UNDO_REQUEST_INVALID, + + /* + * When backend or discard worker push the request to undo worker queue the + * status will be set to this. Undo workers pulls such requests from the + * queues, change the state as UNDO_REQUEST_INPROGRESS and process the undo + * actions. + */ + UNDO_REQUEST_INQUEUE, + + /* + * Undo action execution is in progress either by backend or by undo worker. + */ + UNDO_REQUEST_INPROGRESS +} UndoRequestStatus; + +/* + * UndoRequestIsValid + * True iff undo request status is not invalid. + */ +#define UndoRequestIsValid(rh) \ + ((bool) ((rh->status) != UNDO_REQUEST_INVALID)) + + /* + * UndoRequestIsInProgress + * True iff undo request status is in progress. + */ +#define UndoRequestIsInProgress(rh) \ + ((bool) ((rh->status) == UNDO_REQUEST_INPROGRESS)) + +/* + * UndoRequestIsInQueue + * True iff undo request status is in queue. + */ +#define UndoRequestIsInQueue(rh) \ + ((bool) ((rh->status) == UNDO_REQUEST_INQUEUE)) + +/* This is the data structure for each hash table entry for rollbacks. */ +typedef struct RollbackHashEntry +{ + FullTransactionId full_xid; /* must be first entry */ + UndoRecPtr start_urec_ptr; + UndoRecPtr end_urec_ptr; + UndoRecPtr last_log_start_urec_ptr; + Oid dbid; + UndoRequestStatus status; /* current state of the entry. */ +} RollbackHashEntry; + +/* + * This is the data structure for each hash table key for rollbacks. We need + * to keep start_urec_ptr as a key element because in the same transaction, + * there could be rollback requests for both logged and unlogged relations. + */ +typedef struct RollbackHashKey +{ + FullTransactionId full_xid; + UndoRecPtr start_urec_ptr; +} RollbackHashKey; + +/* This is an entry for undo request queue that is sorted by xid. */ +typedef struct UndoXidQueue +{ + FullTransactionId full_xid; + UndoRecPtr start_urec_ptr; + Oid dbid; +} UndoXidQueue; + +/* This is an entry for undo request queue that is sorted by size. */ +typedef struct UndoSizeQueue +{ + FullTransactionId full_xid; + UndoRecPtr start_urec_ptr; + Oid dbid; + uint64 request_size; +} UndoSizeQueue; + +/* + * This is an entry for undo request queue that is sorted by time at which an + * error has occurred. + */ +typedef struct UndoErrorQueue +{ + FullTransactionId full_xid; + UndoRecPtr start_urec_ptr; + Oid dbid; + TimestampTz next_retry_at; + TimestampTz err_occurred_at; +} UndoErrorQueue; + +/* undo request information */ +typedef struct UndoRequestInfo +{ + FullTransactionId full_xid; + UndoRecPtr start_urec_ptr; + UndoRecPtr end_urec_ptr; + UndoRecPtr last_log_start_urec_ptr; + Oid dbid; + uint64 request_size; + UndoWorkerQueueType undo_worker_queue; +} UndoRequestInfo; + +/* Reset the undo request info */ +#define ResetUndoRequestInfo(urinfo) \ +( \ + (urinfo)->full_xid = InvalidFullTransactionId, \ + (urinfo)->start_urec_ptr = InvalidUndoRecPtr, \ + (urinfo)->end_urec_ptr = InvalidUndoRecPtr, \ + (urinfo)->last_log_start_urec_ptr = InvalidUndoRecPtr, \ + (urinfo)->dbid = InvalidOid, \ + (urinfo)->request_size = 0, \ + (urinfo)->undo_worker_queue = InvalidUndoWorkerQueue \ +) + +/* set the undo request info from the rollback request */ +#define SetUndoRequestInfoFromRHEntry(urinfo, rh, cur_queue) \ +( \ + urinfo->full_xid = rh->full_xid, \ + urinfo->start_urec_ptr = rh->start_urec_ptr, \ + urinfo->end_urec_ptr = rh->end_urec_ptr, \ + urinfo->last_log_start_urec_ptr = rh->last_log_start_urec_ptr, \ + urinfo->dbid = rh->dbid, \ + urinfo->undo_worker_queue = cur_queue \ +) + +/* + * From an undo log if all the undo actions have been applied for a particular + * transaction, we set the uur_progress of the transaction's log in that undo + * log as MaxBlockNumber. If none of the undo actions have yet been applied, + * we set it to InvalidBlockNumber. + */ +#define XACT_APPLY_PROGRESS_COMPLETED MaxBlockNumber +#define XACT_APPLY_PROGRESS_NOT_STARTED InvalidBlockNumber + +#define IsXactApplyProgressCompleted(uur_progress) \ + (uur_progress == XACT_APPLY_PROGRESS_COMPLETED) + +#define IsXactApplyProgressNotStarted(uur_progress) \ + (uur_progress == XACT_APPLY_PROGRESS_NOT_STARTED) + +/* Exposed functions for rollback request queues. */ +extern int PendingUndoShmemSize(void); +extern void PendingUndoShmemInit(void); +extern bool UndoWorkerQueuesEmpty(void); +extern void InsertRequestIntoUndoQueues(UndoRequestInfo *urinfo); +extern bool InsertRequestIntoErrorUndoQueue(volatile UndoRequestInfo *urinfo); +extern void SetUndoWorkerQueueStart(UndoWorkerQueueType undo_worker_queue); +extern bool UndoGetWork(bool allow_peek, bool is_undo_launcher, + UndoRequestInfo *urinfo, bool *in_other_db); + +/* Exposed functions for rollback hash table. */ +extern uint64 FindUndoEndLocationAndSize(UndoRecPtr start_urecptr, + UndoRecPtr *end_urecptr_out, + UndoRecPtr *last_log_start_urecptr_out, + FullTransactionId full_xid); +extern bool RegisterUndoRequest(UndoRecPtr end_urec_ptr, UndoRecPtr start_urec_ptr, + Oid dbid, FullTransactionId full_xid); +extern void RollbackHTRemoveEntry(FullTransactionId full_xid, + UndoRecPtr start_urec_ptr, bool lock); +extern bool RollbackHTIsFull(void); +extern int UndoRollbackHashTableSize(void); +extern void RollbackHTMarkEntryInvalid(FullTransactionId full_xid, + UndoRecPtr start_urec_ptr); +extern UndoRecPtr RollbackHTGetLastLogStartUrp(FullTransactionId full_xid, + UndoRecPtr start_urec_ptr); +extern FullTransactionId RollbackHTGetOldestFullXid(FullTransactionId oldestXmin); + +/* functions exposed from undoaction.c */ +extern void execute_undo_actions(FullTransactionId full_xid, UndoRecPtr from_urecptr, + UndoRecPtr to_urecptr, bool nopartial); +extern bool execute_undo_actions_page(UndoRecInfo *urp_array, int first_idx, + int last_idx, Oid reloid, FullTransactionId full_xid, + BlockNumber blkno, bool blk_chain_complete); + +#endif /* _UNDOREQUEST_H */ diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h index 61a24c2..1afc4d3 100644 --- a/src/include/miscadmin.h +++ b/src/include/miscadmin.h @@ -426,6 +426,7 @@ extern void pg_split_opts(char **argv, int *argcp, const char *optstr); extern void InitializeMaxBackends(void); extern void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, char *out_dbname, bool override_allow_connections); +extern bool dbid_exists(Oid dboid); extern void BaseInit(void); /* in utils/init/miscinit.c */ diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index ac7ee72..824f6bf 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -272,6 +272,8 @@ typedef struct PROC_HDR int startupProcPid; /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ int startupBufferPinWaitBufId; + /* Number of aborted transactions with pending undo actions. */ + int xactsHavingPendingUndo; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; -- 1.8.3.1 [application/octet-stream] 0011-Infrastructure-to-execute-pending-undo-actions.patch (38.7K, ../../CAA4eK1+McY0qGaak0AHyzdgAn+F6dyxcpDwp9ifGg=1WVDadeQ@mail.gmail.com/12-0011-Infrastructure-to-execute-pending-undo-actions.patch) download | inline diff: From 3ea90121dd8f7df14b08ffd9a1fde2f944615495 Mon Sep 17 00:00:00 2001 From: Amit Kapila <[email protected]> Date: Thu, 13 Jun 2019 15:27:58 +0530 Subject: [PATCH 11/13] Infrastructure to execute pending undo actions. To apply the undo actions, we collect the undo records in bulk and try to process them together. We ensure to update the transaction's progress at regular intervals so that after a crash we can skip already applied undo. This provides a way for users to register a callback for processing the undo records based on resource manager. Dilip Kumar, Amit Kapila, Thomas Munro and Kuntal Ghosh with inputs from Robert Haas --- src/backend/access/rmgrdesc/Makefile | 3 +- src/backend/access/rmgrdesc/undoactiondesc.c | 47 +++ src/backend/access/transam/rmgr.c | 5 +- src/backend/access/undo/Makefile | 3 +- src/backend/access/undo/undoaccess.c | 43 ++- src/backend/access/undo/undoaction.c | 524 +++++++++++++++++++++++++++ src/backend/access/undo/undoactionxlog.c | 60 +++ src/backend/replication/logical/decode.c | 1 + src/bin/pg_rewind/parsexlog.c | 2 +- src/bin/pg_waldump/rmgrdesc.c | 3 +- src/include/access/rmgr.h | 2 +- src/include/access/rmgrlist.h | 52 +-- src/include/access/undoaccess.h | 4 + src/include/access/undoaction_xlog.h | 39 ++ src/include/access/undorecord.h | 2 + src/include/access/undorequest.h | 3 - src/include/access/xlog_internal.h | 18 +- 17 files changed, 773 insertions(+), 38 deletions(-) create mode 100644 src/backend/access/rmgrdesc/undoactiondesc.c create mode 100644 src/backend/access/undo/undoaction.c create mode 100644 src/backend/access/undo/undoactionxlog.c create mode 100644 src/include/access/undoaction_xlog.h diff --git a/src/backend/access/rmgrdesc/Makefile b/src/backend/access/rmgrdesc/Makefile index 91ad1ef..640d37f 100644 --- a/src/backend/access/rmgrdesc/Makefile +++ b/src/backend/access/rmgrdesc/Makefile @@ -11,6 +11,7 @@ include $(top_builddir)/src/Makefile.global OBJS = brindesc.o clogdesc.o committsdesc.o dbasedesc.o genericdesc.o \ gindesc.o gistdesc.o hashdesc.o heapdesc.o logicalmsgdesc.o \ mxactdesc.o nbtdesc.o relmapdesc.o replorigindesc.o seqdesc.o \ - smgrdesc.o spgdesc.o standbydesc.o tblspcdesc.o undologdesc.o xactdesc.o xlogdesc.o + smgrdesc.o spgdesc.o standbydesc.o tblspcdesc.o undoactiondesc.o \ + undologdesc.o xactdesc.o xlogdesc.o include $(top_srcdir)/src/backend/common.mk diff --git a/src/backend/access/rmgrdesc/undoactiondesc.c b/src/backend/access/rmgrdesc/undoactiondesc.c new file mode 100644 index 0000000..c396582 --- /dev/null +++ b/src/backend/access/rmgrdesc/undoactiondesc.c @@ -0,0 +1,47 @@ +/*------------------------------------------------------------------------- + * + * undoactiondesc.c + * rmgr descriptor routines for access/undo/undoactionxlog.c + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/backend/access/rmgrdesc/undoactiondesc.c + * + *------------------------------------------------------------------------- + */ +#include "postgres.h" + +#include "access/undoaction_xlog.h" + +void +undoaction_desc(StringInfo buf, XLogReaderState *record) +{ + char *rec = XLogRecGetData(record); + uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK; + + if (info == XLOG_UNDO_APPLY_PROGRESS) + { + xl_undoapply_progress *xlrec = (xl_undoapply_progress *) rec; + + appendStringInfo(buf, "urec_ptr %lu progress %u", + xlrec->urec_ptr, xlrec->progress); + } +} + +const char * +undoaction_identify(uint8 info) +{ + const char *id = NULL; + + switch (info & ~XLR_INFO_MASK) + { + case XLOG_UNDO_APPLY_PROGRESS: + id = "UNDO_APPLY_PROGRESS"; + break; + } + + return id; +} diff --git a/src/backend/access/transam/rmgr.c b/src/backend/access/transam/rmgr.c index 8b05374..c57eca2 100644 --- a/src/backend/access/transam/rmgr.c +++ b/src/backend/access/transam/rmgr.c @@ -18,6 +18,7 @@ #include "access/multixact.h" #include "access/nbtxlog.h" #include "access/spgxlog.h" +#include "access/undoaction_xlog.h" #include "access/undolog_xlog.h" #include "access/xact.h" #include "access/xlog_internal.h" @@ -31,8 +32,8 @@ #include "utils/relmapper.h" /* must be kept in sync with RmgrData definition in xlog_internal.h */ -#define PG_RMGR(symname,name,redo,desc,identify,startup,cleanup,mask) \ - { name, redo, desc, identify, startup, cleanup, mask }, +#define PG_RMGR(symname,name,redo,desc,identify,startup,cleanup,mask,undo,undo_status,undo_desc) \ + { name, redo, desc, identify, startup, cleanup, mask, undo, undo_status, undo_desc }, const RmgrData RmgrTable[RM_MAX_ID + 1] = { #include "access/rmgrlist.h" diff --git a/src/backend/access/undo/Makefile b/src/backend/access/undo/Makefile index 7327502..68696bc 100644 --- a/src/backend/access/undo/Makefile +++ b/src/backend/access/undo/Makefile @@ -12,6 +12,7 @@ subdir = src/backend/access/undo top_builddir = ../../../.. include $(top_builddir)/src/Makefile.global -OBJS = undoaccess.o undolog.o undorecord.o undorequest.o +OBJS = undoaccess.o undoaction.o undoactionxlog.o undolog.o undorecord.o \ + undorequest.o include $(top_srcdir)/src/backend/common.mk diff --git a/src/backend/access/undo/undoaccess.c b/src/backend/access/undo/undoaccess.c index 4ffec58..c215ba1 100644 --- a/src/backend/access/undo/undoaccess.c +++ b/src/backend/access/undo/undoaccess.c @@ -84,8 +84,6 @@ static UnpackedUndoRecord *UndoGetOneRecord(UnpackedUndoRecord *urec, Buffer *prevbuf); static int UndoRecordPrepareTransInfo(UndoRecordInsertContext *context, UndoRecPtr xact_urp, int size, int offset); -static void UndoRecordUpdateTransInfo(UndoRecordInsertContext *context, - int idx); static void UndoRecordPrepareUpdateNext(UndoRecordInsertContext *context, UndoRecPtr urecptr, UndoRecPtr xact_urp); static int UndoGetBufferSlot(UndoRecordInsertContext *context, @@ -285,6 +283,45 @@ UndoRecordPrepareUpdateNext(UndoRecordInsertContext *context, } /* + * Prepare to update the undo apply progress in the transaction header. + */ +void +UndoRecordPrepareApplyProgress(UndoRecordInsertContext *context, + UndoRecPtr xact_urp, BlockNumber progress) +{ + int index = 0; + int offset; + + Assert(UndoRecPtrIsValid(xact_urp)); + + /* + * Temporary undo logs are discarded on transaction commit so we don't + * need to do anything. + */ + if (UndoRecPtrGetCategory(xact_urp) == UNDO_TEMP) + return; + + /* + * Here, we are preparing to update the undo apply progress of a + * transaction being rolled back. The undo must not be discarded + * till the transaction is completely rolled back. + */ + Assert(!UndoRecPtrIsDiscarded(xact_urp)); + + /* Compute the offset of the urec_progress in the undo record. */ + offset = SizeOfUndoRecordHeader + + offsetof(UndoRecordTransaction, urec_progress); + + index = UndoRecordPrepareTransInfo(context, xact_urp, + sizeof(UndoRecPtr), offset); + /* + * Set the undo action progress in xact_urec_info, this will be overwritten + * in actual undo record during update phase. + */ + context->xact_urec_info[index].progress = progress; +} + +/* * Overwrite the first undo record of the previous transaction to update its * next pointer. * @@ -292,7 +329,7 @@ UndoRecordPrepareUpdateNext(UndoRecordInsertContext *context, * This must be called under the critical section. This will just overwrite the * header of the undo record. */ -static void +void UndoRecordUpdateTransInfo(UndoRecordInsertContext *context, int idx) { Page page = NULL; diff --git a/src/backend/access/undo/undoaction.c b/src/backend/access/undo/undoaction.c new file mode 100644 index 0000000..2c6beae --- /dev/null +++ b/src/backend/access/undo/undoaction.c @@ -0,0 +1,524 @@ +/*------------------------------------------------------------------------- + * + * undoaction.c + * execute undo actions + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/backend/access/undo/undoaction.c + * + * To apply the undo actions, we collect the undo records in bulk and try to + * process them together. We ensure to update the transaction's progress at + * regular intervals so that after a crash we can skip already applied undo. + * The undo apply progress is updated in terms of the number of blocks + * processed. Undo apply progress value XACT_APPLY_PROGRESS_COMPLETED + * indicates that all the undo is applied, XACT_APPLY_PROGRESS_NOT_STARTED + * indicates that no undo action has been applied yet and any other value + * indicates that we have applied undo partially and after crash recovery, we + * need to start processing the undo from the same location. + *------------------------------------------------------------------------- + */ + +#include "postgres.h" + +#include "access/table.h" +#include "access/undoaction_xlog.h" +#include "access/undolog.h" +#include "access/undorequest.h" +#include "access/xact.h" +#include "access/xloginsert.h" +#include "access/xlog_internal.h" +#include "nodes/pg_list.h" +#include "pgstat.h" +#include "storage/block.h" +#include "storage/buf.h" +#include "storage/bufmgr.h" +#include "utils/relfilenodemap.h" +#include "utils/syscache.h" +#include "miscadmin.h" +#include "storage/shmem.h" + +static void UpdateUndoApplyProgress(UndoRecPtr last_log_start_urec_ptr, + BlockNumber block_num); +static bool UndoAlreadyApplied(FullTransactionId full_xid, + UndoRecPtr to_urecptr); +static void ApplyUndo(UndoRecInfo *urecinfo, int nrecords); +static void ProcessAndApplyUndo(FullTransactionId full_xid, + UndoRecPtr from_urecptr, UndoRecPtr to_urecptr, + UndoRecPtr last_log_start_urec_ptr, bool complete_xact); + +/* + * undo_record_comparator - qsort comparator for undo records. + * + * This is used to sort undo records for applying undo actions of the + * transaction. + */ +static int +undo_record_comparator(const void *left, const void *right) +{ + UnpackedUndoRecord *luur = ((UndoRecInfo *) left)->uur; + UnpackedUndoRecord *ruur = ((UndoRecInfo *) right)->uur; + + if (luur->uur_rmid < ruur->uur_rmid) + return -1; + else if (luur->uur_rmid > ruur->uur_rmid) + return 1; + else if (luur->uur_reloid < ruur->uur_reloid) + return -1; + else if (luur->uur_reloid > ruur->uur_reloid) + return 1; + else if (luur->uur_block < ruur->uur_block) + return -1; + else if (luur->uur_block > ruur->uur_block) + return 1; + else if (luur->uur_offset < ruur->uur_offset) + return -1; + else if (luur->uur_offset > ruur->uur_offset) + return 1; + else if (((UndoRecInfo *) left)->index < ((UndoRecInfo *) right)->index) + { + /* + * If records are for the same block and offset, then maintain their + * existing order by comparing their index in the array. + */ + return -1; + } + else + return 1; +} + +/* + * UpdateUndoApplyProgress - Updates how far undo actions from a particular + * log have been applied while rolling back a transaction. This progress is + * measured in terms of undo block number of the undo log till which the + * undo actions have been applied. + */ +static void +UpdateUndoApplyProgress(UndoRecPtr progress_urec_ptr, + BlockNumber block_num) +{ + UndoLogCategory category; + UndoRecordInsertContext context = {{0}}; + + category = + UndoLogNumberGetCategory(UndoRecPtrGetLogNo(progress_urec_ptr)); + + /* + * We don't need to update the progress for temp tables as they get + * discraded after startup. + */ + if (category == UNDO_TEMP) + return; + + BeginUndoRecordInsert(&context, category, 1, NULL); + + /* + * Prepare and update the undo apply progress in the transaction header. + */ + UndoRecordPrepareApplyProgress(&context, progress_urec_ptr, block_num); + + START_CRIT_SECTION(); + + /* Update the progress in the transaction header. */ + UndoRecordUpdateTransInfo(&context, 0); + + /* WAL log the undo apply progress. */ + { + XLogRecPtr lsn; + xl_undoapply_progress xlrec; + + xlrec.urec_ptr = progress_urec_ptr; + xlrec.progress = block_num; + + XLogBeginInsert(); + XLogRegisterData((char *) &xlrec, sizeof(xlrec)); + + RegisterUndoLogBuffers(&context, 1); + lsn = XLogInsert(RM_UNDOACTION_ID, XLOG_UNDO_APPLY_PROGRESS); + UndoLogBuffersSetLSN(&context, lsn); + } + + END_CRIT_SECTION(); + + /* Release undo buffers. */ + FinishUndoRecordInsert(&context); +} + +/* + * UndoAlreadyApplied - Retruns true, if the actions are already applied, + * false, otherwise. + */ +static bool +UndoAlreadyApplied(FullTransactionId full_xid, UndoRecPtr to_urecptr) +{ + UnpackedUndoRecord *uur = NULL; + UndoRecordFetchContext context; + + /* Fetch the undo record. */ + BeginUndoFetch(&context); + uur = UndoFetchRecord(&context, to_urecptr); + FinishUndoFetch(&context); + + /* already processed and discarded */ + if (uur == NULL) + { + /* + * Undo action is already applied, so delete the hash table entry + * if exists. + */ + RollbackHTRemoveEntry(full_xid, to_urecptr, false); + return true; + } + + /* already processed */ + if (IsXactApplyProgressCompleted(uur->uur_txn->urec_progress)) + { + /* + * Undo action is already applied, so delete the hash table entry + * if exists. + */ + RollbackHTRemoveEntry(full_xid, to_urecptr, false); + UndoRecordRelease(uur); + return true; + } + + Assert(FullTransactionIdEquals(full_xid, uur->uur_fxid)); + + UndoRecordRelease(uur); + + return false; +} + +/* + * ApplyUndo - Invode rmgr specific undo apply functions. + * + * urecinfo - An array of undo records sorted in the rmgr order. + * nrecords - number of records in this array. + */ +static void +ApplyUndo(UndoRecInfo *urecinfo, int nrecords) +{ + int rmgr_start_idx = 0; + int rmgr_nrecords = 0; + int prev_rmid = -1; + int i; + + /* Apply the undo action for each rmgr. */ + for (i = 0; i < nrecords; i++) + { + UnpackedUndoRecord *uur = urecinfo[i].uur; + + Assert(uur->uur_rmid >= 0); + + /* + * If this undo is not for the same rmgr then apply all undo + * actions for the previous rmgr. + */ + if (prev_rmid >= 0 && + prev_rmid != uur->uur_rmid) + { + Assert(urecinfo[rmgr_start_idx].uur->uur_rmid == prev_rmid); + RmgrTable[prev_rmid].rm_undo(rmgr_nrecords, + &urecinfo[rmgr_start_idx]); + + rmgr_start_idx = i; + rmgr_nrecords = 0; + } + + rmgr_nrecords++; + prev_rmid = uur->uur_rmid; + } + + /* Apply the last set of the actions. */ + Assert(urecinfo[rmgr_start_idx].uur->uur_rmid == prev_rmid); + RmgrTable[prev_rmid].rm_undo(rmgr_nrecords, &urecinfo[rmgr_start_idx]); +} + +/* + * ProcessAndApplyUndo - Fetch undo records and apply actions. + * + * We always process the undo of the last log when the undo for a transaction + * spans across multiple logs. Then from there onwards the previous undo logs + * for the same transaction are processed. + * + * We also update the undo apply progress in the transaction header so that + * after recovery we don't need to process the records that are already + * processed. As we update the progress only after one batch of records, + * the crash in-between can cause us to read/apply part of undo records + * again but this will never be more than one-batch. We can further optimize + * it by marking the progress in each record, but that has its own downsides + * like it will generate more WAL and I/O corresponding to dirty undo buffers. + */ +static void +ProcessAndApplyUndo(FullTransactionId full_xid, UndoRecPtr from_urecptr, + UndoRecPtr to_urecptr, UndoRecPtr last_log_start_urec_ptr, + bool complete_xact) +{ + UndoRecInfo *urecinfo; + UndoRecPtr urec_ptr = from_urecptr; + int undo_apply_size; + + /* + * We choose maintenance_work_mem to collect the undo records for + * rollbacks as most of the large rollback requests are done by + * background worker which can be considered as maintainence operation. + * However, we can introduce a new guc for this as well. + */ + undo_apply_size = maintenance_work_mem * 1024L; + + /* + * Fetch the multiple undo records that can fit into undo_apply_size; sort + * them and then rmgr specific callback to process them. Repeat this + * until we process all the records for the transaction being rolled back. + */ + while (true) + { + BlockNumber progress_block_num = InvalidBlockNumber; + int i; + int nrecords; + bool log_switched = false; + bool rollback_completed = false; + bool update_progress = false; + UndoRecPtr progress_urec_ptr = InvalidUndoRecPtr; + UndoRecInfo *first_urecinfo; + UndoRecInfo *last_urecinfo; + + CHECK_FOR_INTERRUPTS(); + + /* + * Fetch multiple undo records at once. + * + * At a time, we only fetch the undo records from a single undo log. + * Once, we process all the undo records from one undo log, we update + * the last_log_start_urec_ptr and proceed to the previous undo log. + */ + urecinfo = UndoBulkFetchRecord(&urec_ptr, last_log_start_urec_ptr, + undo_apply_size, &nrecords, false); + + /* + * Since the rollback of this transaction is in-progress, there will be + * at least one undo record which is not yet discarded. + */ + Assert(nrecords > 0); + + /* + * Get the required information from first and last undo record before + * we sort all the records. + */ + first_urecinfo = &urecinfo[0]; + last_urecinfo = &urecinfo[nrecords - 1]; + if (IsUndoLogSwitched(last_urecinfo->uur)) + { + UndoRecordLogSwitch *logswitch = last_urecinfo->uur->uur_logswitch; + + /* + * We have crossed the log boundary. The rest of the undo for + * this transaction is in some other log, the location of which + * can be found from this record. See commets atop undoaccess.c. + */ + log_switched = true; + + /* + * We need to save the undo record pointer of the last record from + * previous undo log. We will use the same as from location in + * next iteration of bulk fetch. + */ + Assert(UndoRecPtrIsValid(logswitch->urec_prevurp)); + urec_ptr = logswitch->urec_prevurp; + + /* + * The last fetched undo record corresponds to the first undo + * record of the current log. Once, the undo actions are performed + * from this log, we've to mark the progress as completed. + */ + progress_urec_ptr = last_urecinfo->urp; + + /* + * We also need to save the start location of this transaction in + * previous log. This will be used in the next iteration of bulk + * fetch and updating progress location. + */ + if (complete_xact) + { + Assert(UndoRecPtrIsValid(logswitch->urec_prevlogstart)); + last_log_start_urec_ptr = logswitch->urec_prevlogstart; + } + + /* We've to update the progress for the current log as completed. */ + update_progress = true; + } + else if (complete_xact) + { + if (UndoRecPtrIsValid(urec_ptr)) + { + /* + * There are still some undo actions pending in this log. So, + * just update the progress block number. + */ + progress_block_num = UndoRecPtrGetBlockNum(last_urecinfo->urp); + + /* + * If we've not fetched undo records for more than one undo + * block, we can't update the progress block number. Because, + * there can still be undo records in this block that needs to + * be applied for rolling back this transaction. + */ + if (UndoRecPtrGetBlockNum(first_urecinfo->urp) > progress_block_num) + { + update_progress = true; + progress_urec_ptr = last_log_start_urec_ptr; + } + } + else + { + /* + * Invalid urec_ptr indicates that we have executed all the undo + * actions for this transaction. So, mark current log header + * as complete. + */ + Assert(last_log_start_urec_ptr == to_urecptr); + rollback_completed = true; + update_progress = true; + progress_urec_ptr = last_log_start_urec_ptr; + } + } + + /* + * The undo records must belong to the transaction that is being + * rolled back. + */ + Assert(FullTransactionIdEquals(full_xid, urecinfo[0].uur->uur_fxid)); + + /* Sort the undo record array in order of target blocks. */ + qsort((void *) urecinfo, nrecords, sizeof(UndoRecInfo), + undo_record_comparator); + + /* Call resource manager specific callbacks to apply actions. */ + ApplyUndo(urecinfo, nrecords); + + /* Set undo action apply progress if required. */ + if (update_progress) + { + Assert(UndoRecPtrIsValid(progress_urec_ptr)); + + if (log_switched || rollback_completed) + { + /* + * We have crossed the log boundary or executed all the undo + * actions for the main transaction. So, mark current log + * header as complete and set the next progress location in + * the previous log. + */ + UpdateUndoApplyProgress(progress_urec_ptr, + XACT_APPLY_PROGRESS_COMPLETED); + } + else + { + /* + * Update the progress block number. We increase the block + * number by one since the current block might have some undo + * records that are yet to be applied. But, all undo records + * from the next block must have been applied. + */ + UpdateUndoApplyProgress(progress_urec_ptr, + progress_block_num + 1); + } + } + + /* Free all undo records. */ + for (i = 0; i < nrecords; i++) + UndoRecordRelease(urecinfo[i].uur); + + /* Free urp array for the current batch of undo records. */ + pfree(urecinfo); + + /* + * Invalid urec_ptr indicates that we have executed all the undo + * actions for this transaction. + */ + if (!UndoRecPtrIsValid(urec_ptr)) + break; + } +} + +/* + * execute_undo_actions - Execute the undo actions + * + * full_xid - Transaction id that is getting rolled back. + * from_urecptr - undo record pointer from where to start applying undo + * actions. + * to_urecptr - undo record pointer up to which the undo actions need to be + * applied. + * complete_xact - true if rollback is for complete transaction. + */ +void +execute_undo_actions(FullTransactionId full_xid, UndoRecPtr from_urecptr, + UndoRecPtr to_urecptr, bool complete_xact) +{ + UndoRecPtr last_log_start_urec_ptr = to_urecptr; + + /* 'from' and 'to' pointers must be valid. */ + Assert(UndoRecPtrIsValid(from_urecptr)); + Assert(UndoRecPtrIsValid(to_urecptr)); + + /* + * Here we compute the last log start urp which is used for fetching the + * undo records and updating the undo action progress. + * + * For rollbacks of subtransaction, we won't be able to calculate the last + * log start urp since we don't have the start urp of the top xid and hence + * we won't be able to follow the transaction chains to find the last log. + */ + if (complete_xact) + { + if (UndoRecPtrGetCategory(to_urecptr) == UNDO_TEMP) + { + UndoRecPtr end_urec_ptr = from_urecptr; + + /* + * For temporary tables, we don't push the rollback request in the + * rollback hash table so we can't directly get the last log start + * urp from there. Instead, we need to compute it now. + */ + (void) FindUndoEndLocationAndSize(to_urecptr, &end_urec_ptr, + &last_log_start_urec_ptr, + full_xid); + } + else + { + /* + * It is important here to fetch the latest undo record and validate if + * the actions are already executed. The reason is that it is possible + * that discard worker or backend might try to execute the rollback + * request which is already executed. For ex., after discard worker + * fetches the record and found that this transaction need to be + * rolledback, backend might concurrently execute the actions and + * remove the request from rollback hash table. + * + * The other case where this will be required is when the transactions + * records span across multiple logs. Say, we register the + * transaction from the first log and then we encounter the same + * transaction in the second log where its status is still not marked + * as done. Now, before we try to register the request for the second + * log, the undo worker came along rolled back the previous request + * and removed its hash entry. In this case, we will successfully + * register the request from the second log and it should be detected + * here. + */ + if (UndoAlreadyApplied(full_xid, to_urecptr)) + return; + + last_log_start_urec_ptr = + RollbackHTGetLastLogStartUrp(full_xid, to_urecptr); + } + } + + ProcessAndApplyUndo(full_xid, from_urecptr, to_urecptr, + last_log_start_urec_ptr, complete_xact); + + /* + * Undo actions are applied so delete the hash table entry. + */ + RollbackHTRemoveEntry(full_xid, to_urecptr, false); +} diff --git a/src/backend/access/undo/undoactionxlog.c b/src/backend/access/undo/undoactionxlog.c new file mode 100644 index 0000000..8d4ff7f --- /dev/null +++ b/src/backend/access/undo/undoactionxlog.c @@ -0,0 +1,60 @@ +/*------------------------------------------------------------------------- + * + * undoactionxlog.c + * WAL replay logic for undo actions. + * + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/backend/access/undo/undoactionxlog.c + * + *------------------------------------------------------------------------- + */ +#include "postgres.h" + +#include "access/undoaction_xlog.h" +#include "access/undoaccess.h" +#include "access/xlog.h" +#include "access/xlogutils.h" + +/* + * Replay of undo apply progress. + */ +static void +undo_xlog_apply_progress(XLogReaderState *record) +{ + xl_undoapply_progress *xlrec = (xl_undoapply_progress *) XLogRecGetData(record); + UndoLogCategory category; + UndoRecordInsertContext context = {{0}}; + + category = + UndoLogNumberGetCategory(UndoRecPtrGetLogNo(xlrec->urec_ptr)); + + BeginUndoRecordInsert(&context, category, 1, record); + + /* Update the undo apply progress in the transaction header. */ + UndoRecordPrepareApplyProgress(&context, xlrec->urec_ptr, + xlrec->progress); + + UndoRecordUpdateTransInfo(&context, 0); + + /* Release undo buffers. */ + FinishUndoRecordInsert(&context); +} + +void +undoaction_redo(XLogReaderState *record) +{ + uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK; + + switch (info) + { + case XLOG_UNDO_APPLY_PROGRESS: + undo_xlog_apply_progress(record); + break; + default: + elog(PANIC, "undoaction_redo: unknown op code %u", info); + } +} diff --git a/src/backend/replication/logical/decode.c b/src/backend/replication/logical/decode.c index d3a9c4d..272edcb 100644 --- a/src/backend/replication/logical/decode.c +++ b/src/backend/replication/logical/decode.c @@ -155,6 +155,7 @@ LogicalDecodingProcessRecord(LogicalDecodingContext *ctx, XLogReaderState *recor case RM_REPLORIGIN_ID: case RM_GENERIC_ID: case RM_UNDOLOG_ID: + case RM_UNDOACTION_ID: /* just deal with xid, and done */ ReorderBufferProcessXid(ctx->reorder, XLogRecGetXid(record), buf.origptr); diff --git a/src/bin/pg_rewind/parsexlog.c b/src/bin/pg_rewind/parsexlog.c index 287af60..b26c45e 100644 --- a/src/bin/pg_rewind/parsexlog.c +++ b/src/bin/pg_rewind/parsexlog.c @@ -28,7 +28,7 @@ * RmgrNames is an array of resource manager names, to make error messages * a bit nicer. */ -#define PG_RMGR(symname,name,redo,desc,identify,startup,cleanup,mask) \ +#define PG_RMGR(symname,name,redo,desc,identify,startup,cleanup,mask,undo,undo_status,undo_desc) \ name, static const char *RmgrNames[RM_MAX_ID + 1] = { diff --git a/src/bin/pg_waldump/rmgrdesc.c b/src/bin/pg_waldump/rmgrdesc.c index 938150d..976f80e 100644 --- a/src/bin/pg_waldump/rmgrdesc.c +++ b/src/bin/pg_waldump/rmgrdesc.c @@ -20,6 +20,7 @@ #include "access/nbtxlog.h" #include "access/rmgr.h" #include "access/spgxlog.h" +#include "access/undoaction_xlog.h" #include "access/undolog_xlog.h" #include "access/xact.h" #include "access/xlog_internal.h" @@ -33,7 +34,7 @@ #include "storage/standbydefs.h" #include "utils/relmapper.h" -#define PG_RMGR(symname,name,redo,desc,identify,startup,cleanup,mask) \ +#define PG_RMGR(symname,name,redo,desc,identify,startup,cleanup,mask,undo,undo_status,undo_desc) \ { name, desc, identify}, const RmgrDescData RmgrDescTable[RM_MAX_ID + 1] = { diff --git a/src/include/access/rmgr.h b/src/include/access/rmgr.h index c9b5c56..0a3794a 100644 --- a/src/include/access/rmgr.h +++ b/src/include/access/rmgr.h @@ -19,7 +19,7 @@ typedef uint8 RmgrId; * Note: RM_MAX_ID must fit in RmgrId; widening that type will affect the XLOG * file format. */ -#define PG_RMGR(symname,name,redo,desc,identify,startup,cleanup,mask) \ +#define PG_RMGR(symname,name,redo,desc,identify,startup,cleanup,mask,undo,undo_status,undo_desc) \ symname, typedef enum RmgrIds diff --git a/src/include/access/rmgrlist.h b/src/include/access/rmgrlist.h index 6945e3e..b424c3c 100644 --- a/src/include/access/rmgrlist.h +++ b/src/include/access/rmgrlist.h @@ -24,27 +24,31 @@ * Changes to this list possibly need an XLOG_PAGE_MAGIC bump. */ -/* symbol name, textual name, redo, desc, identify, startup, cleanup */ -PG_RMGR(RM_XLOG_ID, "XLOG", xlog_redo, xlog_desc, xlog_identify, NULL, NULL, NULL) -PG_RMGR(RM_XACT_ID, "Transaction", xact_redo, xact_desc, xact_identify, NULL, NULL, NULL) -PG_RMGR(RM_SMGR_ID, "Storage", smgr_redo, smgr_desc, smgr_identify, NULL, NULL, NULL) -PG_RMGR(RM_CLOG_ID, "CLOG", clog_redo, clog_desc, clog_identify, NULL, NULL, NULL) -PG_RMGR(RM_DBASE_ID, "Database", dbase_redo, dbase_desc, dbase_identify, NULL, NULL, NULL) -PG_RMGR(RM_TBLSPC_ID, "Tablespace", tblspc_redo, tblspc_desc, tblspc_identify, NULL, NULL, NULL) -PG_RMGR(RM_MULTIXACT_ID, "MultiXact", multixact_redo, multixact_desc, multixact_identify, NULL, NULL, NULL) -PG_RMGR(RM_RELMAP_ID, "RelMap", relmap_redo, relmap_desc, relmap_identify, NULL, NULL, NULL) -PG_RMGR(RM_STANDBY_ID, "Standby", standby_redo, standby_desc, standby_identify, NULL, NULL, NULL) -PG_RMGR(RM_HEAP2_ID, "Heap2", heap2_redo, heap2_desc, heap2_identify, NULL, NULL, heap_mask) -PG_RMGR(RM_HEAP_ID, "Heap", heap_redo, heap_desc, heap_identify, NULL, NULL, heap_mask) -PG_RMGR(RM_BTREE_ID, "Btree", btree_redo, btree_desc, btree_identify, NULL, NULL, btree_mask) -PG_RMGR(RM_HASH_ID, "Hash", hash_redo, hash_desc, hash_identify, NULL, NULL, hash_mask) -PG_RMGR(RM_GIN_ID, "Gin", gin_redo, gin_desc, gin_identify, gin_xlog_startup, gin_xlog_cleanup, gin_mask) -PG_RMGR(RM_GIST_ID, "Gist", gist_redo, gist_desc, gist_identify, gist_xlog_startup, gist_xlog_cleanup, gist_mask) -PG_RMGR(RM_SEQ_ID, "Sequence", seq_redo, seq_desc, seq_identify, NULL, NULL, seq_mask) -PG_RMGR(RM_SPGIST_ID, "SPGist", spg_redo, spg_desc, spg_identify, spg_xlog_startup, spg_xlog_cleanup, spg_mask) -PG_RMGR(RM_BRIN_ID, "BRIN", brin_redo, brin_desc, brin_identify, NULL, NULL, brin_mask) -PG_RMGR(RM_COMMIT_TS_ID, "CommitTs", commit_ts_redo, commit_ts_desc, commit_ts_identify, NULL, NULL, NULL) -PG_RMGR(RM_REPLORIGIN_ID, "ReplicationOrigin", replorigin_redo, replorigin_desc, replorigin_identify, NULL, NULL, NULL) -PG_RMGR(RM_GENERIC_ID, "Generic", generic_redo, generic_desc, generic_identify, NULL, NULL, generic_mask) -PG_RMGR(RM_LOGICALMSG_ID, "LogicalMessage", logicalmsg_redo, logicalmsg_desc, logicalmsg_identify, NULL, NULL, NULL) -PG_RMGR(RM_UNDOLOG_ID, "UndoLog", undolog_redo, undolog_desc, undolog_identify, NULL, NULL, NULL) +/* + * symbol name, textual name, redo, desc, identify, startup, cleanup, mask, + * undo, undo_status, undo_desc + */ +PG_RMGR(RM_XLOG_ID, "XLOG", xlog_redo, xlog_desc, xlog_identify, NULL, NULL, NULL, NULL, NULL, NULL) +PG_RMGR(RM_XACT_ID, "Transaction", xact_redo, xact_desc, xact_identify, NULL, NULL, NULL, NULL, NULL, NULL) +PG_RMGR(RM_SMGR_ID, "Storage", smgr_redo, smgr_desc, smgr_identify, NULL, NULL, NULL, NULL, NULL, NULL) +PG_RMGR(RM_CLOG_ID, "CLOG", clog_redo, clog_desc, clog_identify, NULL, NULL, NULL, NULL, NULL, NULL) +PG_RMGR(RM_DBASE_ID, "Database", dbase_redo, dbase_desc, dbase_identify, NULL, NULL, NULL, NULL, NULL, NULL) +PG_RMGR(RM_TBLSPC_ID, "Tablespace", tblspc_redo, tblspc_desc, tblspc_identify, NULL, NULL, NULL, NULL, NULL, NULL) +PG_RMGR(RM_MULTIXACT_ID, "MultiXact", multixact_redo, multixact_desc, multixact_identify, NULL, NULL, NULL, NULL, NULL, NULL) +PG_RMGR(RM_RELMAP_ID, "RelMap", relmap_redo, relmap_desc, relmap_identify, NULL, NULL, NULL, NULL, NULL, NULL) +PG_RMGR(RM_STANDBY_ID, "Standby", standby_redo, standby_desc, standby_identify, NULL, NULL, NULL, NULL, NULL, NULL) +PG_RMGR(RM_HEAP2_ID, "Heap2", heap2_redo, heap2_desc, heap2_identify, NULL, NULL, heap_mask, NULL, NULL, NULL) +PG_RMGR(RM_HEAP_ID, "Heap", heap_redo, heap_desc, heap_identify, NULL, NULL, heap_mask, NULL, NULL, NULL) +PG_RMGR(RM_BTREE_ID, "Btree", btree_redo, btree_desc, btree_identify, NULL, NULL, btree_mask, NULL, NULL, NULL) +PG_RMGR(RM_HASH_ID, "Hash", hash_redo, hash_desc, hash_identify, NULL, NULL, hash_mask, NULL, NULL, NULL) +PG_RMGR(RM_GIN_ID, "Gin", gin_redo, gin_desc, gin_identify, gin_xlog_startup, gin_xlog_cleanup, gin_mask, NULL, NULL, NULL) +PG_RMGR(RM_GIST_ID, "Gist", gist_redo, gist_desc, gist_identify, gist_xlog_startup, gist_xlog_cleanup, gist_mask, NULL, NULL, NULL) +PG_RMGR(RM_SEQ_ID, "Sequence", seq_redo, seq_desc, seq_identify, NULL, NULL, seq_mask, NULL, NULL, NULL) +PG_RMGR(RM_SPGIST_ID, "SPGist", spg_redo, spg_desc, spg_identify, spg_xlog_startup, spg_xlog_cleanup, spg_mask, NULL, NULL, NULL) +PG_RMGR(RM_BRIN_ID, "BRIN", brin_redo, brin_desc, brin_identify, NULL, NULL, brin_mask, NULL, NULL, NULL) +PG_RMGR(RM_COMMIT_TS_ID, "CommitTs", commit_ts_redo, commit_ts_desc, commit_ts_identify, NULL, NULL, NULL, NULL, NULL, NULL) +PG_RMGR(RM_REPLORIGIN_ID, "ReplicationOrigin", replorigin_redo, replorigin_desc, replorigin_identify, NULL, NULL, NULL, NULL, NULL, NULL) +PG_RMGR(RM_GENERIC_ID, "Generic", generic_redo, generic_desc, generic_identify, NULL, NULL, generic_mask, NULL, NULL, NULL) +PG_RMGR(RM_LOGICALMSG_ID, "LogicalMessage", logicalmsg_redo, logicalmsg_desc, logicalmsg_identify, NULL, NULL, NULL, NULL, NULL, NULL) +PG_RMGR(RM_UNDOLOG_ID, "UndoLog", undolog_redo, undolog_desc, undolog_identify, NULL, NULL, NULL, NULL, NULL, NULL) +PG_RMGR(RM_UNDOACTION_ID, "UndoAction", undoaction_redo, undoaction_desc, undoaction_identify, NULL, NULL, NULL, NULL, NULL, NULL) diff --git a/src/include/access/undoaccess.h b/src/include/access/undoaccess.h index 24ea97b..7c31332 100644 --- a/src/include/access/undoaccess.h +++ b/src/include/access/undoaccess.h @@ -13,6 +13,7 @@ #ifndef UNDOACCESS_H #define UNDOACCESS_H +#include "access/transam.h" #include "access/undolog.h" #include "access/undorecord.h" #include "access/xlogdefs.h" @@ -94,6 +95,9 @@ typedef struct UndoRecordFetchContext UndoRecPtr urp; /* Previous undo record pointer. */ } UndoRecordFetchContext; +extern void UndoRecordPrepareApplyProgress(UndoRecordInsertContext *context, + UndoRecPtr urecptr, BlockNumber progress); +extern void UndoRecordUpdateTransInfo(UndoRecordInsertContext *context, int idx); extern void BeginUndoRecordInsert(UndoRecordInsertContext *context, UndoLogCategory category, int nprepared, diff --git a/src/include/access/undoaction_xlog.h b/src/include/access/undoaction_xlog.h new file mode 100644 index 0000000..b9e65d1 --- /dev/null +++ b/src/include/access/undoaction_xlog.h @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + * + * undoaction_xlog.h + * undo action XLOG definitions + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/undoaction_xlog.h + * + *------------------------------------------------------------------------- + */ +#ifndef UNDOACTION_XLOG_H +#define UNDOACTION_XLOG_H + +#include "access/undolog.h" +#include "access/xlogreader.h" +#include "lib/stringinfo.h" +#include "storage/off.h" + +/* + * WAL record definitions for undoactions.c's WAL operations + */ +#define XLOG_UNDO_APPLY_PROGRESS 0x00 + +/* This is what we need to know about undo apply progress */ +typedef struct xl_undoapply_progress +{ + UndoRecPtr urec_ptr; + uint32 progress; +} xl_undoapply_progress; + +#define SizeOfUndoActionProgress (offsetof(xl_undoapply_progress, progress) + sizeof(uint32)) + +extern void undoaction_redo(XLogReaderState *record); +extern void undoaction_desc(StringInfo buf, XLogReaderState *record); +extern const char *undoaction_identify(uint8 info); + +#endif /* UNDOACTION_XLOG_H */ diff --git a/src/include/access/undorecord.h b/src/include/access/undorecord.h index 6a2c5cc..9232cf5 100644 --- a/src/include/access/undorecord.h +++ b/src/include/access/undorecord.h @@ -260,6 +260,8 @@ typedef struct UnpackedUndoRecord * during a transaction. */ } UnpackedUndoRecord; +#define IsUndoLogSwitched(uur) (uur->uur_logswitch != NULL) + extern Size UndoRecordHeaderSize(uint16 uur_info); extern Size UndoRecordExpectedSize(UnpackedUndoRecord *uur); extern Size UnpackedUndoRecordSize(UnpackedUndoRecord *uur); diff --git a/src/include/access/undorequest.h b/src/include/access/undorequest.h index 64d89ba..82640b8 100644 --- a/src/include/access/undorequest.h +++ b/src/include/access/undorequest.h @@ -224,8 +224,5 @@ extern FullTransactionId RollbackHTGetOldestFullXid(FullTransactionId oldestXmin /* functions exposed from undoaction.c */ extern void execute_undo_actions(FullTransactionId full_xid, UndoRecPtr from_urecptr, UndoRecPtr to_urecptr, bool nopartial); -extern bool execute_undo_actions_page(UndoRecInfo *urp_array, int first_idx, - int last_idx, Oid reloid, FullTransactionId full_xid, - BlockNumber blkno, bool blk_chain_complete); #endif /* _UNDOREQUEST_H */ diff --git a/src/include/access/xlog_internal.h b/src/include/access/xlog_internal.h index b986a385..35aff69 100644 --- a/src/include/access/xlog_internal.h +++ b/src/include/access/xlog_internal.h @@ -19,10 +19,14 @@ #ifndef XLOG_INTERNAL_H #define XLOG_INTERNAL_H +#include "access/transam.h" +#include "access/undoaccess.h" +#include "access/undorecord.h" #include "access/xlogdefs.h" #include "access/xlogreader.h" #include "datatype/timestamp.h" #include "lib/stringinfo.h" +#include "nodes/pg_list.h" #include "pgtime.h" #include "storage/block.h" #include "storage/relfilenode.h" @@ -271,6 +275,15 @@ typedef enum } RecoveryTargetAction; /* + * Return values for undo status callback functions. + */ +typedef enum UndoStatus +{ + UNDO_STATUS_WAIT_XMIN, /* wait until the xmin passes an xid */ + UNDO_STATUS_DISCARD /* the record set should be discarded */ +} UndoStatus; + +/* * Method table for resource managers. * * This struct must be kept in sync with the PG_RMGR definition in @@ -295,9 +308,12 @@ typedef struct RmgrData void (*rm_startup) (void); void (*rm_cleanup) (void); void (*rm_mask) (char *pagedata, BlockNumber blkno); + void (*rm_undo) (int nrecords, UndoRecInfo *records); + UndoStatus (*rm_undo_status) (UnpackedUndoRecord *record, TransactionId *xid); + void (*rm_undo_desc) (StringInfo buf, UnpackedUndoRecord *record); } RmgrData; -extern const RmgrData RmgrTable[]; +extern PGDLLIMPORT const RmgrData RmgrTable[]; /* * Exported to support xlog switching from checkpointer -- 1.8.3.1 [application/octet-stream] 0012-Allow-foreground-transactions-to-perform-undo-action.patch (51.7K, ../../CAA4eK1+McY0qGaak0AHyzdgAn+F6dyxcpDwp9ifGg=1WVDadeQ@mail.gmail.com/13-0012-Allow-foreground-transactions-to-perform-undo-action.patch) download | inline diff: From 6973e1d5edba3025aad7d4023bc19d89951b6e86 Mon Sep 17 00:00:00 2001 From: Amit Kapila <[email protected]> Date: Thu, 13 Jun 2019 15:42:46 +0530 Subject: [PATCH 12/13] Allow foreground transactions to perform undo actions on abort. We always perform rollback actions after cleaning up the current (sub)transaction. This will ensure that we perform the actions immediately after an error (and release the locks) rather than when the user issues Rollback command at some later point of time. We are releasing the locks after the undo actions are applied. The reason to delay lock release is that if we release locks before applying undo actions, then the parallel session can acquire the lock before us which can lead to deadlock. Amit Kapila and Dilip Kumar with inputs from Robert Haas --- src/backend/access/transam/twophase.c | 82 ++++- src/backend/access/transam/varsup.c | 24 ++ src/backend/access/transam/xact.c | 497 +++++++++++++++++++++++++- src/backend/access/undo/README.UndoProcessing | 39 ++ src/backend/access/undo/undoaccess.c | 7 + src/backend/access/undo/undoaction.c | 23 +- src/backend/storage/ipc/ipc.c | 7 + src/backend/tcop/postgres.c | 8 +- src/backend/utils/error/elog.c | 23 +- src/backend/utils/init/globals.c | 1 + src/backend/utils/resowner/resowner.c | 11 +- src/include/access/transam.h | 1 + src/include/access/twophase.h | 3 +- src/include/access/xact.h | 11 + src/include/miscadmin.h | 15 + src/include/utils/elog.h | 2 + 16 files changed, 727 insertions(+), 27 deletions(-) create mode 100644 src/backend/access/undo/README.UndoProcessing diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index 477709b..4d34d11 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -82,6 +82,7 @@ #include "access/transam.h" #include "access/twophase.h" #include "access/twophase_rmgr.h" +#include "access/undorequest.h" #include "access/xact.h" #include "access/xlog.h" #include "access/xloginsert.h" @@ -909,7 +910,7 @@ TwoPhaseGetDummyProc(TransactionId xid, bool lock_held) /* * Header for a 2PC state file */ -#define TWOPHASE_MAGIC 0x57F94534 /* format identifier */ +#define TWOPHASE_MAGIC 0x57F94535 /* format identifier */ typedef struct TwoPhaseFileHeader { @@ -927,6 +928,16 @@ typedef struct TwoPhaseFileHeader uint16 gidlen; /* length of the GID - GID follows the header */ XLogRecPtr origin_lsn; /* lsn of this record at origin node */ TimestampTz origin_timestamp; /* time of prepare at origin node */ + + /* + * We need the locations of the start and end undo record pointers when + * rollbacks are to be performed for prepared transactions using undo-based + * relations. We need to store this information in the file as the user + * might rollback the prepared transaction after recovery and for that we + * need its start and end undo locations. + */ + UndoRecPtr start_urec_ptr[UndoLogCategories]; + UndoRecPtr end_urec_ptr[UndoLogCategories]; } TwoPhaseFileHeader; /* @@ -1001,7 +1012,8 @@ save_state_data(const void *data, uint32 len) * Initializes data structure and inserts the 2PC file header record. */ void -StartPrepare(GlobalTransaction gxact) +StartPrepare(GlobalTransaction gxact, UndoRecPtr *start_urec_ptr, + UndoRecPtr *end_urec_ptr) { PGPROC *proc = &ProcGlobal->allProcs[gxact->pgprocno]; PGXACT *pgxact = &ProcGlobal->allPgXact[gxact->pgprocno]; @@ -1032,6 +1044,11 @@ StartPrepare(GlobalTransaction gxact) hdr.database = proc->databaseId; hdr.prepared_at = gxact->prepared_at; hdr.owner = gxact->owner; + + /* save the start and end undo record pointers */ + memcpy(hdr.start_urec_ptr, start_urec_ptr, sizeof(hdr.start_urec_ptr)); + memcpy(hdr.end_urec_ptr, end_urec_ptr, sizeof(hdr.end_urec_ptr)); + hdr.nsubxacts = xactGetCommittedChildren(&children); hdr.ncommitrels = smgrGetPendingDeletes(true, &commitrels); hdr.nabortrels = smgrGetPendingDeletes(false, &abortrels); @@ -1468,6 +1485,12 @@ FinishPreparedTransaction(const char *gid, bool isCommit) RelFileNode *delrels; int ndelrels; SharedInvalidationMessage *invalmsgs; + UndoRecPtr startUrecPtr[UndoLogCategories]; + UndoRecPtr endUrecPtr[UndoLogCategories]; + bool uRequestRegistered[UndoLogCategories]; + uint32 epoch; + int i; + FullTransactionId fXid; /* * Validate the GID, and lock the GXACT to ensure that two backends do not @@ -1505,6 +1528,10 @@ FinishPreparedTransaction(const char *gid, bool isCommit) invalmsgs = (SharedInvalidationMessage *) bufptr; bufptr += MAXALIGN(hdr->ninvalmsgs * sizeof(SharedInvalidationMessage)); + /* save the start and end undo record pointers */ + memcpy(startUrecPtr, hdr->start_urec_ptr, sizeof(startUrecPtr)); + memcpy(endUrecPtr, hdr->end_urec_ptr, sizeof(endUrecPtr)); + /* compute latestXid among all children */ latestXid = TransactionIdLatest(xid, hdr->nsubxacts, children); @@ -1518,6 +1545,13 @@ FinishPreparedTransaction(const char *gid, bool isCommit) * TransactionIdIsInProgress will stop saying the prepared xact is in * progress), then run the post-commit or post-abort callbacks. The * callbacks will release the locks the transaction held. + * + * XXX Note that, unlike non-prepared transactions, we don't skip + * releasing the locks when we have to perform the undo actions. The + * reason is that here the locks are not directly associated with current + * transaction, rather it has to acquire those locks to apply undo actions. + * So, if we don't release the locks for prepared transaction, the undo + * applying transaction will wait forever. */ if (isCommit) RecordTransactionCommitPrepared(xid, @@ -1526,10 +1560,36 @@ FinishPreparedTransaction(const char *gid, bool isCommit) hdr->ninvalmsgs, invalmsgs, hdr->initfileinval, gid); else + { + /* + * We don't allow XIDs with an age of more than 2 billion in undo, so + * we can infer the epoch here. (XXX We can add full transaction id in + * TwoPhaseFileHeader instead.) + */ + epoch = GetEpochForXid(hdr->xid); + fXid = FullTransactionIdFromEpochAndXid(epoch, hdr->xid); + + /* + * Register the rollback request to apply undo actions. It is + * important to do this before marking it aborted in clog, see + * comments atop CheckAndRegisterUndoRequest for further details. + */ + for (i = 0; i < UndoLogCategories; i++) + { + if (endUrecPtr[i] != InvalidUndoRecPtr && i != UNDO_TEMP) + { + uRequestRegistered[i] = RegisterUndoRequest(endUrecPtr[i], + startUrecPtr[i], + hdr->database, + fXid); + } + } + RecordTransactionAbortPrepared(xid, hdr->nsubxacts, children, hdr->nabortrels, abortrels, gid); + } ProcArrayRemove(proc, latestXid); @@ -1614,6 +1674,24 @@ FinishPreparedTransaction(const char *gid, bool isCommit) RESUME_INTERRUPTS(); + if (!isCommit) + { + /* + * We need to perform undo actions while we are still in a transaction. + */ + if (!ProcessUndoRequestForEachLogCat(fXid, hdr->database, + endUrecPtr, startUrecPtr, + uRequestRegistered, false)) + { + /* Abort the failed transaction. */ + AbortOutOfAnyTransaction(); + FlushErrorState(); + + /* Restart our transaction. */ + StartTransactionCommand(); + } + } + pfree(buf); } diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c index 5b759ec..fd01989 100644 --- a/src/backend/access/transam/varsup.c +++ b/src/backend/access/transam/varsup.c @@ -566,3 +566,27 @@ GetNewObjectId(void) return result; } + +/* + * Get epoch for the given xid. + */ +uint32 +GetEpochForXid(TransactionId xid) +{ + FullTransactionId next_fxid; + TransactionId next_xid; + uint32 epoch; + + next_fxid = ReadNextFullTransactionId(); + next_xid = XidFromFullTransactionId(next_fxid); + epoch = EpochFromFullTransactionId(next_fxid); + + /* + * If xid is numerically bigger than next_xid, it has to be from the last + * epoch. + */ + if (unlikely(xid > next_xid)) + epoch--; + + return epoch; +} diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index d7930c0..fbbe585 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -26,6 +26,7 @@ #include "access/subtrans.h" #include "access/transam.h" #include "access/twophase.h" +#include "access/undorequest.h" #include "access/xact.h" #include "access/xlog.h" #include "access/xloginsert.h" @@ -128,7 +129,8 @@ typedef enum TransState TRANS_INPROGRESS, /* inside a valid transaction */ TRANS_COMMIT, /* commit in progress */ TRANS_ABORT, /* abort in progress */ - TRANS_PREPARE /* prepare in progress */ + TRANS_PREPARE, /* prepare in progress */ + TRANS_UNDO /* undo apply in progress */ } TransState; /* @@ -153,6 +155,7 @@ typedef enum TBlockState TBLOCK_ABORT_END, /* failed xact, ROLLBACK received */ TBLOCK_ABORT_PENDING, /* live xact, ROLLBACK received */ TBLOCK_PREPARE, /* live xact, PREPARE received */ + TBLOCK_UNDO, /* failed xact, awaiting undo to be applied */ /* subtransaction states */ TBLOCK_SUBBEGIN, /* starting a subtransaction */ @@ -163,7 +166,8 @@ typedef enum TBlockState TBLOCK_SUBABORT_END, /* failed subxact, ROLLBACK received */ TBLOCK_SUBABORT_PENDING, /* live subxact, ROLLBACK received */ TBLOCK_SUBRESTART, /* live subxact, ROLLBACK TO received */ - TBLOCK_SUBABORT_RESTART /* failed subxact, ROLLBACK TO received */ + TBLOCK_SUBABORT_RESTART, /* failed subxact, ROLLBACK TO received */ + TBLOCK_SUBUNDO /* failed subxact, awaiting undo to be applied */ } TBlockState; /* @@ -191,6 +195,16 @@ typedef struct TransactionStateData bool didLogXid; /* has xid been included in WAL record? */ int parallelModeLevel; /* Enter/ExitParallelMode counter */ bool chain; /* start a new block after this one */ + + /* start and end undo record location for each log category */ + UndoRecPtr startUrecPtr[UndoLogCategories]; /* this is 'to' location */ + UndoRecPtr latestUrecPtr[UndoLogCategories]; /* this is 'from' + * location */ + /* + * whether the undo request is registered to be processed by worker later? + */ + bool undoRequestResgistered[UndoLogCategories]; + struct TransactionStateData *parent; /* back link to parent */ } TransactionStateData; @@ -339,6 +353,7 @@ static void ShowTransactionState(const char *str); static void ShowTransactionStateRec(const char *str, TransactionState state); static const char *BlockStateAsString(TBlockState blockState); static const char *TransStateAsString(TransState state); +static void CheckAndRegisterUndoRequest(void); /* ---------------------------------------------------------------- @@ -362,9 +377,9 @@ IsTransactionState(void) * also reject the startup/shutdown states TRANS_START, TRANS_COMMIT, * TRANS_PREPARE since it might be too soon or too late within those * transition states to do anything interesting. Hence, the only "valid" - * state is TRANS_INPROGRESS. + * state is TRANS_INPROGRESS or TRANS_UNDO. */ - return (s->state == TRANS_INPROGRESS); + return (s->state == TRANS_INPROGRESS || s->state == TRANS_UNDO); } /* @@ -723,9 +738,14 @@ SubTransactionIsActive(SubTransactionId subxid) { TransactionState s; + /* + * The subtransaction is not considered active if it is being aborted or + * in undo apply state, even though it may still have an entry on the + * state stack. + */ for (s = CurrentTransactionState; s != NULL; s = s->parent) { - if (s->state == TRANS_ABORT) + if (s->state == TRANS_ABORT || s->state == TRANS_UNDO) continue; if (s->subTransactionId == subxid) return true; @@ -905,15 +925,15 @@ TransactionIdIsCurrentTransactionId(TransactionId xid) * We will return true for the Xid of the current subtransaction, any of * its subcommitted children, any of its parents, or any of their * previously subcommitted children. However, a transaction being aborted - * is no longer "current", even though it may still have an entry on the - * state stack. + * or in undo apply state is no longer "current", even though it may still + * have an entry on the state stack. */ for (s = CurrentTransactionState; s != NULL; s = s->parent) { int low, high; - if (s->state == TRANS_ABORT) + if (s->state == TRANS_ABORT || s->state == TRANS_UNDO) continue; if (!FullTransactionIdIsValid(s->fullTransactionId)) continue; /* it can't have any child XIDs either */ @@ -1968,6 +1988,14 @@ StartTransaction(void) nUnreportedXids = 0; s->didLogXid = false; + /* initialize undo information for the transaction */ + memset(s->startUrecPtr, InvalidUndoRecPtr, + sizeof(UndoRecPtr) * UndoLogCategories); + memset(s->latestUrecPtr, InvalidUndoRecPtr, + sizeof(UndoRecPtr) * UndoLogCategories); + memset(s->undoRequestResgistered, false, + sizeof(bool) * UndoLogCategories); + /* * must initialize resource-management stuff first */ @@ -2264,6 +2292,8 @@ CommitTransaction(void) XactTopFullTransactionId = InvalidFullTransactionId; nParallelCurrentXids = 0; + ResetUndoActionsInfo(); + /* * done with commit processing, set current transaction state back to * default @@ -2433,7 +2463,7 @@ PrepareTransaction(void) * PREPARED; in particular, pay attention to whether things should happen * before or after releasing the transaction's locks. */ - StartPrepare(gxact); + StartPrepare(gxact, s->startUrecPtr, s->latestUrecPtr); AtPrepare_Notify(); AtPrepare_Locks(); @@ -2566,6 +2596,7 @@ AbortTransaction(void) TransactionState s = CurrentTransactionState; TransactionId latestXid; bool is_parallel_worker; + bool undo_apply_in_progress; /* Prevent cancel/die interrupt while cleaning up */ HOLD_INTERRUPTS(); @@ -2622,7 +2653,10 @@ AbortTransaction(void) * check the current transaction state */ is_parallel_worker = (s->blockState == TBLOCK_PARALLEL_INPROGRESS); - if (s->state != TRANS_INPROGRESS && s->state != TRANS_PREPARE) + undo_apply_in_progress = (s->blockState == TBLOCK_UNDO); + if (s->state != TRANS_INPROGRESS && + s->state != TRANS_PREPARE && + s->state != TRANS_UNDO) elog(WARNING, "AbortTransaction while in %s state", TransStateAsString(s->state)); Assert(s->parent == NULL); @@ -2666,11 +2700,12 @@ AbortTransaction(void) * Advertise the fact that we aborted in pg_xact (assuming that we got as * far as assigning an XID to advertise). But if we're inside a parallel * worker, skip this; the user backend must be the one to write the abort - * record. + * record. Also, skip this if undo apply is in progress as in that case + * we would have already written abort record. */ - if (!is_parallel_worker) + if (!is_parallel_worker && !undo_apply_in_progress) latestXid = RecordTransactionAbort(false); - else + else if (is_parallel_worker) { latestXid = InvalidTransactionId; @@ -2780,6 +2815,8 @@ CleanupTransaction(void) XactTopFullTransactionId = InvalidFullTransactionId; nParallelCurrentXids = 0; + ResetUndoActionsInfo(); + /* * done with abort processing, set current transaction state back to * default @@ -2845,6 +2882,8 @@ StartTransactionCommand(void) case TBLOCK_SUBRESTART: case TBLOCK_SUBABORT_RESTART: case TBLOCK_PREPARE: + case TBLOCK_UNDO: + case TBLOCK_SUBUNDO: elog(ERROR, "StartTransactionCommand: unexpected state %s", BlockStateAsString(s->blockState)); break; @@ -2906,9 +2945,18 @@ CommitTransactionCommand(void) * StartTransactionCommand didn't set the STARTED state * appropriately, while TBLOCK_PARALLEL_INPROGRESS should be ended * by EndParallelWorkerTransaction(), not this function. + * + * TBLOCK_(SUB)UNDO means the error has occurred while applying + * undo for a (sub)transaction. We can't reach here as while + * applying undo via top-level transaction, if we get an error, + * then it is handled by ReleaseResourcesAndProcessUndo and for + * subtransaction, we promote the error to fatal in such a + * situation. */ case TBLOCK_DEFAULT: case TBLOCK_PARALLEL_INPROGRESS: + case TBLOCK_UNDO: + case TBLOCK_SUBUNDO: elog(FATAL, "CommitTransactionCommand: unexpected state %s", BlockStateAsString(s->blockState)); break; @@ -2987,11 +3035,13 @@ CommitTransactionCommand(void) /* * Here we were in a perfectly good transaction block but the user - * told us to ROLLBACK anyway. We have to abort the transaction - * and then clean up. + * told us to ROLLBACK anyway. We have to abort the transaction, + * apply the undo actions if any and then clean up. */ case TBLOCK_ABORT_PENDING: + CheckAndRegisterUndoRequest(); AbortTransaction(); + ReleaseResourcesAndProcessUndo(); CleanupTransaction(); s->blockState = TBLOCK_DEFAULT; if (s->chain) @@ -3087,7 +3137,9 @@ CommitTransactionCommand(void) * As above, but it's not dead yet, so abort first. */ case TBLOCK_SUBABORT_PENDING: + CheckAndRegisterUndoRequest(); AbortSubTransaction(); + ReleaseResourcesAndProcessUndo(); CleanupSubTransaction(); CommitTransactionCommand(); break; @@ -3107,7 +3159,9 @@ CommitTransactionCommand(void) s->name = NULL; savepointLevel = s->savepointLevel; + CheckAndRegisterUndoRequest(); AbortSubTransaction(); + ReleaseResourcesAndProcessUndo(); CleanupSubTransaction(); DefineSavepoint(NULL); @@ -3175,7 +3229,11 @@ AbortCurrentTransaction(void) * incompletely started transaction. First, adjust the * low-level state to suppress warning message from * AbortTransaction. + * + * In this state, we must not have performed any operation + * which can generate undo. */ + Assert(!NeedToPerformUndoActions()); if (s->state == TRANS_START) s->state = TRANS_INPROGRESS; AbortTransaction(); @@ -3190,7 +3248,9 @@ AbortCurrentTransaction(void) */ case TBLOCK_STARTED: case TBLOCK_IMPLICIT_INPROGRESS: + CheckAndRegisterUndoRequest(); AbortTransaction(); + ReleaseResourcesAndProcessUndo(); CleanupTransaction(); s->blockState = TBLOCK_DEFAULT; break; @@ -3201,8 +3261,12 @@ AbortCurrentTransaction(void) * will interpret the error as meaning the BEGIN failed to get him * into a transaction block, so we should abort and return to idle * state. + * + * In this state, we must not have performed any operation which + * which can generate undo. */ case TBLOCK_BEGIN: + Assert(!NeedToPerformUndoActions()); AbortTransaction(); CleanupTransaction(); s->blockState = TBLOCK_DEFAULT; @@ -3215,7 +3279,9 @@ AbortCurrentTransaction(void) */ case TBLOCK_INPROGRESS: case TBLOCK_PARALLEL_INPROGRESS: + CheckAndRegisterUndoRequest(); AbortTransaction(); + ReleaseResourcesAndProcessUndo(); s->blockState = TBLOCK_ABORT; /* CleanupTransaction happens when we exit TBLOCK_ABORT_END */ break; @@ -3226,7 +3292,9 @@ AbortCurrentTransaction(void) * the transaction). */ case TBLOCK_END: + CheckAndRegisterUndoRequest(); AbortTransaction(); + ReleaseResourcesAndProcessUndo(); CleanupTransaction(); s->blockState = TBLOCK_DEFAULT; break; @@ -3255,7 +3323,9 @@ AbortCurrentTransaction(void) * Abort, cleanup, go to idle state. */ case TBLOCK_ABORT_PENDING: + CheckAndRegisterUndoRequest(); AbortTransaction(); + ReleaseResourcesAndProcessUndo(); CleanupTransaction(); s->blockState = TBLOCK_DEFAULT; break; @@ -3266,7 +3336,9 @@ AbortCurrentTransaction(void) * the transaction). */ case TBLOCK_PREPARE: + CheckAndRegisterUndoRequest(); AbortTransaction(); + ReleaseResourcesAndProcessUndo(); CleanupTransaction(); s->blockState = TBLOCK_DEFAULT; break; @@ -3277,7 +3349,9 @@ AbortCurrentTransaction(void) * we get ROLLBACK. */ case TBLOCK_SUBINPROGRESS: + CheckAndRegisterUndoRequest(); AbortSubTransaction(); + ReleaseResourcesAndProcessUndo(); s->blockState = TBLOCK_SUBABORT; break; @@ -3291,7 +3365,9 @@ AbortCurrentTransaction(void) case TBLOCK_SUBCOMMIT: case TBLOCK_SUBABORT_PENDING: case TBLOCK_SUBRESTART: + CheckAndRegisterUndoRequest(); AbortSubTransaction(); + ReleaseResourcesAndProcessUndo(); CleanupSubTransaction(); AbortCurrentTransaction(); break; @@ -3304,6 +3380,19 @@ AbortCurrentTransaction(void) CleanupSubTransaction(); AbortCurrentTransaction(); break; + + /* + * The error occurred while applying undo for a (sub)transaction. + * We can't reach here as while applying undo via top-level + * transaction, if we get an error, then it is handled by + * ReleaseResourcesAndProcessUndo and for subtransaction, we + * promote the error to fatal in such a situation. + */ + case TBLOCK_UNDO: + case TBLOCK_SUBUNDO: + elog(FATAL, "AbortCurrentTransaction: unexpected state %s", + BlockStateAsString(s->blockState)); + break; } } @@ -3633,6 +3722,8 @@ BeginTransactionBlock(void) case TBLOCK_SUBRESTART: case TBLOCK_SUBABORT_RESTART: case TBLOCK_PREPARE: + case TBLOCK_UNDO: + case TBLOCK_SUBUNDO: elog(FATAL, "BeginTransactionBlock: unexpected state %s", BlockStateAsString(s->blockState)); break; @@ -3825,6 +3916,8 @@ EndTransactionBlock(bool chain) case TBLOCK_SUBRESTART: case TBLOCK_SUBABORT_RESTART: case TBLOCK_PREPARE: + case TBLOCK_UNDO: + case TBLOCK_SUBUNDO: elog(FATAL, "EndTransactionBlock: unexpected state %s", BlockStateAsString(s->blockState)); break; @@ -3941,6 +4034,8 @@ UserAbortTransactionBlock(bool chain) case TBLOCK_SUBRESTART: case TBLOCK_SUBABORT_RESTART: case TBLOCK_PREPARE: + case TBLOCK_UNDO: + case TBLOCK_SUBUNDO: elog(FATAL, "UserAbortTransactionBlock: unexpected state %s", BlockStateAsString(s->blockState)); break; @@ -4081,6 +4176,8 @@ DefineSavepoint(const char *name) case TBLOCK_SUBRESTART: case TBLOCK_SUBABORT_RESTART: case TBLOCK_PREPARE: + case TBLOCK_UNDO: + case TBLOCK_SUBUNDO: elog(FATAL, "DefineSavepoint: unexpected state %s", BlockStateAsString(s->blockState)); break; @@ -4157,6 +4254,8 @@ ReleaseSavepoint(const char *name) case TBLOCK_SUBRESTART: case TBLOCK_SUBABORT_RESTART: case TBLOCK_PREPARE: + case TBLOCK_UNDO: + case TBLOCK_SUBUNDO: elog(FATAL, "ReleaseSavepoint: unexpected state %s", BlockStateAsString(s->blockState)); break; @@ -4266,6 +4365,8 @@ RollbackToSavepoint(const char *name) case TBLOCK_SUBRESTART: case TBLOCK_SUBABORT_RESTART: case TBLOCK_PREPARE: + case TBLOCK_UNDO: + case TBLOCK_SUBUNDO: elog(FATAL, "RollbackToSavepoint: unexpected state %s", BlockStateAsString(s->blockState)); break; @@ -4384,6 +4485,8 @@ BeginInternalSubTransaction(const char *name) case TBLOCK_SUBABORT_PENDING: case TBLOCK_SUBRESTART: case TBLOCK_SUBABORT_RESTART: + case TBLOCK_UNDO: + case TBLOCK_SUBUNDO: elog(FATAL, "BeginInternalSubTransaction: unexpected state %s", BlockStateAsString(s->blockState)); break; @@ -4473,17 +4576,25 @@ RollbackAndReleaseCurrentSubTransaction(void) case TBLOCK_SUBRESTART: case TBLOCK_SUBABORT_RESTART: case TBLOCK_PREPARE: + case TBLOCK_UNDO: + case TBLOCK_SUBUNDO: elog(FATAL, "RollbackAndReleaseCurrentSubTransaction: unexpected state %s", BlockStateAsString(s->blockState)); break; } + /* Try to push rollback request to worker if possible. */ + CheckAndRegisterUndoRequest(); + /* * Abort the current subtransaction, if needed. */ if (s->blockState == TBLOCK_SUBINPROGRESS) AbortSubTransaction(); + /* Execute undo actions */ + ReleaseResourcesAndProcessUndo(); + /* And clean it up, too */ CleanupSubTransaction(); @@ -4529,7 +4640,11 @@ AbortOutOfAnyTransaction(void) * incompletely started transaction. First, adjust the * low-level state to suppress warning message from * AbortTransaction. + * + * In this state, we must not have performed any operation + * which can generate undo. */ + Assert(!NeedToPerformUndoActions()); if (s->state == TRANS_START) s->state = TRANS_INPROGRESS; AbortTransaction(); @@ -4545,6 +4660,19 @@ AbortOutOfAnyTransaction(void) case TBLOCK_ABORT_PENDING: case TBLOCK_PREPARE: /* In a transaction, so clean up */ + CheckAndRegisterUndoRequest(); + AbortTransaction(); + ReleaseResourcesAndProcessUndo(); + CleanupTransaction(); + s->blockState = TBLOCK_DEFAULT; + break; + case TBLOCK_UNDO: + /* + * We reach here when we got error while applying undo + * actions, so we don't want to again start applying it. Undo + * workers can take care of it. + */ + ResetUndoActionsInfo(); AbortTransaction(); CleanupTransaction(); s->blockState = TBLOCK_DEFAULT; @@ -4572,7 +4700,9 @@ AbortOutOfAnyTransaction(void) case TBLOCK_SUBCOMMIT: case TBLOCK_SUBABORT_PENDING: case TBLOCK_SUBRESTART: + CheckAndRegisterUndoRequest(); AbortSubTransaction(); + ReleaseResourcesAndProcessUndo(); CleanupSubTransaction(); s = CurrentTransactionState; /* changed by pop */ break; @@ -4592,6 +4722,17 @@ AbortOutOfAnyTransaction(void) CleanupSubTransaction(); s = CurrentTransactionState; /* changed by pop */ break; + case TBLOCK_SUBUNDO: + /* + * We reach here when we got error while applying undo + * actions, so we don't want to again start applying it. Undo + * workers can take care of it. + */ + ResetUndoActionsInfo(); + AbortSubTransaction(); + CleanupSubTransaction(); + s = CurrentTransactionState; /* changed by pop */ + break; } } while (s->blockState != TBLOCK_DEFAULT); @@ -4666,6 +4807,8 @@ TransactionBlockStatusCode(void) case TBLOCK_SUBABORT_PENDING: case TBLOCK_SUBRESTART: case TBLOCK_SUBABORT_RESTART: + case TBLOCK_UNDO: + case TBLOCK_SUBUNDO: return 'E'; /* in failed transaction */ } @@ -4722,6 +4865,14 @@ StartSubTransaction(void) AtSubStart_Notify(); AfterTriggerBeginSubXact(); + /* initialize undo information for the transaction */ + memset(s->startUrecPtr, InvalidUndoRecPtr, + sizeof(UndoRecPtr) * UndoLogCategories); + memset(s->latestUrecPtr, InvalidUndoRecPtr, + sizeof(UndoRecPtr) * UndoLogCategories); + memset(s->undoRequestResgistered, false, + sizeof(bool) * UndoLogCategories); + s->state = TRANS_INPROGRESS; /* @@ -4743,6 +4894,7 @@ static void CommitSubTransaction(void) { TransactionState s = CurrentTransactionState; + int i; ShowTransactionState("CommitSubTransaction"); @@ -4765,6 +4917,19 @@ CommitSubTransaction(void) /* Do the actual "commit", such as it is */ s->state = TRANS_COMMIT; + /* + * Propagate the undo pointers from current transaction to parent so that + * if parent transaction get aborted we must not skip performing undo for + * this transaction. + */ + for (i = 0; i < UndoLogCategories; i++) + { + if (UndoRecPtrIsValid(s->latestUrecPtr[i])) + s->parent->latestUrecPtr[i] = s->latestUrecPtr[i]; + if (!UndoRecPtrIsValid(s->parent->startUrecPtr[i])) + s->parent->startUrecPtr[i] = s->startUrecPtr[i]; + } + /* Must CCI to ensure commands of subtransaction are seen as done */ CommandCounterIncrement(); @@ -4852,6 +5017,7 @@ static void AbortSubTransaction(void) { TransactionState s = CurrentTransactionState; + bool undo_apply_in_progress; /* Prevent cancel/die interrupt while cleaning up */ HOLD_INTERRUPTS(); @@ -4909,7 +5075,10 @@ AbortSubTransaction(void) */ ShowTransactionState("AbortSubTransaction"); - if (s->state != TRANS_INPROGRESS) + undo_apply_in_progress = (s->blockState == TBLOCK_SUBUNDO); + + if (s->state != TRANS_INPROGRESS && + s->state != TRANS_UNDO) elog(WARNING, "AbortSubTransaction while in %s state", TransStateAsString(s->state)); @@ -4943,8 +5112,13 @@ AbortSubTransaction(void) s->parent->subTransactionId); AtSubAbort_Notify(); - /* Advertise the fact that we aborted in pg_xact. */ - (void) RecordTransactionAbort(true); + /* + * Advertise the fact that we aborted in pg_xact. But if undo apply + * is in progress then skip this as in that case we would have already + * written abort record. + */ + if (!undo_apply_in_progress) + (void) RecordTransactionAbort(true); /* Post-abort cleanup */ if (FullTransactionIdIsValid(s->fullTransactionId)) @@ -5336,6 +5510,8 @@ BlockStateAsString(TBlockState blockState) return "ABORT_PENDING"; case TBLOCK_PREPARE: return "PREPARE"; + case TBLOCK_UNDO: + return "UNDO"; case TBLOCK_SUBBEGIN: return "SUBBEGIN"; case TBLOCK_SUBINPROGRESS: @@ -5354,6 +5530,8 @@ BlockStateAsString(TBlockState blockState) return "SUBRESTART"; case TBLOCK_SUBABORT_RESTART: return "SUBABORT_RESTART"; + case TBLOCK_SUBUNDO: + return "SUBUNDO"; } return "UNRECOGNIZED"; } @@ -5379,6 +5557,8 @@ TransStateAsString(TransState state) return "ABORT"; case TRANS_PREPARE: return "PREPARE"; + case TRANS_UNDO: + return "UNDO"; } return "UNRECOGNIZED"; } @@ -5977,3 +6157,284 @@ xact_redo(XLogReaderState *record) else elog(PANIC, "xact_redo: unknown op code %u", info); } + +/* + * SetCurrentUndoLocation + * + * Sets the 'from' and 'to' location for the current transaction. + */ +void +SetCurrentUndoLocation(UndoRecPtr urec_ptr, UndoLogCategory category) +{ + /* + * Set the start undo record pointer for first undo record in a + * subtransaction. + */ + if (!UndoRecPtrIsValid(CurrentTransactionState->startUrecPtr[category])) + CurrentTransactionState->startUrecPtr[category] = urec_ptr; + CurrentTransactionState->latestUrecPtr[category] = urec_ptr; +} + +/* + * ResetUndoActionsInfo - reset the start and end undo record pointers. + */ +void +ResetUndoActionsInfo(void) +{ + TransactionState s = CurrentTransactionState; + + /* initialize undo information for the transaction */ + memset(s->startUrecPtr, InvalidUndoRecPtr, + sizeof(UndoRecPtr) * UndoLogCategories); + memset(s->latestUrecPtr, InvalidUndoRecPtr, + sizeof(UndoRecPtr) * UndoLogCategories); + memset(s->undoRequestResgistered, false, + sizeof(bool) * UndoLogCategories); +} + +/* + * NeedToPerformUndoActions - Returns true, if the current transaction needs + * to perform undo actions, false otherwise. + * + * This function needs to be called before we release the locks during abort + * so that we can skip releasing them if required. We don't release the locks + * till we execute undo actions otherwise, there is a risk of deadlock. + */ +bool +NeedToPerformUndoActions(void) +{ + TransactionState s = CurrentTransactionState; + int i; + + for (i = 0; i < UndoLogCategories; i++) + { + if (UndoRecPtrIsValid(s->latestUrecPtr[i])) + return true; + } + + return false; +} + +/* + * CheckAndRegisterUndoRequest - Register the request for applying undo + * actions. + * + * It sets the transaction state to indicate whether the request is pushed to + * the background worker which is used later to decide whether to apply the + * actions. + * + * It is important to do this before marking the transaction as aborted in + * clog otherwise, it is quite possible that discard worker miss this rollback + * request from the computation of oldestXidHavingUnappliedUndo. This is + * because it might do that computation before backend can register it in the + * rollback hash table. So, neither oldestXmin computation will consider it + * nor the hash table pass would have that value. + */ +static void +CheckAndRegisterUndoRequest() +{ + TransactionState s = CurrentTransactionState; + bool result; + int i; + + /* + * We don't want to apply the undo actions when we are already cleaning up + * for FATAL error. See ReleaseResourcesAndProcessUndo. + */ + if (SemiCritSectionCount > 0) + { + ResetUndoActionsInfo(); + return; + } + + if (!NeedToPerformUndoActions()) + return; + /* + * We can't postpone applying undo actions for subtransactions as the + * modifications made by aborted subtransaction must not be visible even if + * the main transaction commits. See execute_undo_actions for detailed + * explanation. + */ + if (IsSubTransaction()) + return; + + for (i = 0; i < UndoLogCategories; i++) + { + /* + * We can't push the undo actions for temp table to background + * workers as the the temp tables are only accessible in the + * backend that has created them. + */ + if (i != UNDO_TEMP && UndoRecPtrIsValid(s->latestUrecPtr[i])) + { + result = RegisterUndoRequest(s->latestUrecPtr[i], + s->startUrecPtr[i], + MyDatabaseId, + GetTopFullTransactionId()); + s->undoRequestResgistered[i] = result; + } + } +} + +/* + * ReleaseResourcesAndProcessUndo - Release resources and process undo request. + * + * To execute undo actions during abort, we bring the transaction to a clean + * state by releasing the required resources and put it in a new state + * TRANS_UNDO. + * + * Note that we release locks after applying undo actions. We skip them + * during Abort(Sub)Transaction as otherwise there is always a risk of + * deadlock when we need to re-take them during processing of undo actions. + */ +void +ReleaseResourcesAndProcessUndo(void) +{ + TransactionState s = CurrentTransactionState; + + /* + * We don't want to apply the undo actions when we are already cleaning up + * for FATAL error. One of the main reasons is that we might be already + * processing undo actions for a (sub)transaction when we reach here + * (for ex. error happens while processing undo actions for a + * subtransaction). + */ + if (SemiCritSectionCount > 0) + { + ResetUndoActionsInfo(); + return; + } + + if (!NeedToPerformUndoActions()) + return; + + /* + * State should still be TRANS_ABORT from AbortTransaction(). + */ + if (s->state != TRANS_ABORT) + elog(FATAL, "ReleaseResourcesAndProcessUndo: unexpected state %s", + TransStateAsString(s->state)); + + /* + * Do abort cleanup processing before applying the undo actions. We must + * do this before applying the undo actions to remove the effects of + * failed transaction. + */ + if (IsSubTransaction()) + { + AtSubCleanup_Portals(s->subTransactionId); + s->blockState = TBLOCK_SUBUNDO; + } + else + { + AtCleanup_Portals(); /* now safe to release portal memory */ + AtEOXact_Snapshot(false, true); /* and release the transaction's + * snapshots */ + s->fullTransactionId = InvalidFullTransactionId; + s->subTransactionId = TopSubTransactionId; + s->blockState = TBLOCK_UNDO; + } + + s->state = TRANS_UNDO; + + /* + * We ignore the return value here as in either case we need to release + * the resources and allow caller to proceed with further cleanup. + */ + (void) ProcessUndoRequestForEachLogCat(GetTopFullTransactionId(), + MyDatabaseId, + s->latestUrecPtr, s->startUrecPtr, + s->undoRequestResgistered, + IsSubTransaction()); + + /* Reset undo information */ + ResetUndoActionsInfo(); + + /* Release the locks after processing undo request. */ + ResourceOwnerRelease(s->curTransactionOwner, + RESOURCE_RELEASE_LOCKS, + false, + !IsSubTransaction()); + + /* + * Here we again put back the transaction in abort state so that callers + * can proceed with the cleanup work. + */ + s->state = TRANS_ABORT; +} + +/* + * ProcessUndoRequestForEachLogCat - Perform undo actions for all the undo logs. + * + * Returns true, if we are able to successfully perform the actions, + * false, otherwise. + * + * If we get any error while performing undo actions, we just insert the + * request into an error queue for later processing by undo launcher and allow + * the main transaction to continue. In such a case the callers are + * responsible to release the resources. + */ +bool +ProcessUndoRequestForEachLogCat(FullTransactionId fxid, Oid dbid, + UndoRecPtr *end_urec_ptr, UndoRecPtr *start_urec_ptr, + bool *undoRequestResgistered, bool isSubTrans) +{ + UndoRequestInfo urinfo; + int i; + uint32 save_holdoff; + bool success = true; + + for (i = 0; i < UndoLogCategories; i++) + { + if (end_urec_ptr[i] && !undoRequestResgistered[i]) + { + save_holdoff = InterruptHoldoffCount; + + PG_TRY(); + { + /* for subtransactions, we do partial rollback. */ + execute_undo_actions(fxid, + end_urec_ptr[i], + start_urec_ptr[i], + !isSubTrans); + } + PG_CATCH(); + { + /* + * Add the request into an error queue so that it can be + * processed in a timely fashion. + * + * If we fail to add the request in an error queue, then mark + * the entry status as invalid and continue to process the + * remaining undo requests if any. This request will be later + * added back to the queue by discard worker. + */ + ResetUndoRequestInfo(&urinfo); + urinfo.dbid = dbid; + urinfo.full_xid = fxid; + urinfo.start_urec_ptr = start_urec_ptr[i]; + if (!InsertRequestIntoErrorUndoQueue(&urinfo)) + RollbackHTMarkEntryInvalid(urinfo.full_xid, + urinfo.start_urec_ptr); + /* + * Errors can reset holdoff count, so restore back. This is + * required because this function can be called after holding + * interrupts. + */ + InterruptHoldoffCount = save_holdoff; + + /* Send the error only to server log. */ + err_out_to_client(false); + EmitErrorReport(); + + success = false; + + /* We should never reach here when we are in a semi-critical-section. */ + Assert(SemiCritSectionCount == 0); + } + PG_END_TRY(); + } + } + + return success; +} diff --git a/src/backend/access/undo/README.UndoProcessing b/src/backend/access/undo/README.UndoProcessing new file mode 100644 index 0000000..e0caf9e --- /dev/null +++ b/src/backend/access/undo/README.UndoProcessing @@ -0,0 +1,39 @@ +src/backend/access/undo/README.UndoProcessing + +Transaction Rollbacks and Undo Processing +------------------------------------------ +We always perform rollback actions after cleaning up the current +(sub)transaction. This will ensure that we perform the actions immediately +after error rather than when user issues Rollback command at some later point +of time. We are releasing the locks after the undo actions are applied. The +reason to delay lock release is that if we release locks before applying undo +actions, then the parallel session can acquire the lock before us which can +lead to deadlock. To execute undo actions during abort, we bring the +transaction to a clean state by releasing the required resources and put it in +a new state TRANS_UNDO which indicates that undo apply is in progress. This +state is considered as a valid state which means that it is safe to initiate a +database access, acquire heavyweight locks, etc. in this state. We have also +introduced new block states TBLOCK_UNDO and TBLOCK_SUBUNDO, so that if we get +an error while applying undo, we don't restart applying it again and rather +just perform Abort/Cleanup of transaction. + +We promote the error to FATAL error if it occurred while applying undo for a +subtransaction. The reason we can't proceed without applying subtransaction's +undo is that the modifications made in that case must not be visible even if +the main transaction commits. Normally, the backends that receive the request +to perform Rollback (To Savepoint) applies the undo actions, but there are +cases where it is preferable to push the requests to background workers. The +main reasons to push the requests to background workers are (a) The rollback +request is very large, pushing such a request to background workers will allow +us to return control to users quickly. There is a guc rollback_overflow_size +which indicates that rollbacks greater than the configured size are performed +lazily by background workers. (b) We got an error while applying the undo +actions. + +We do have some restrictions on which requests can be pushed to the background +workers. In single user mode, all the requests are performed in foreground. +We can't push the undo actions for temp table to background workers as the temp +tables are only accessible in the backend that has created them. We can't +postpone applying undo actions for subtransactions as the modifications +made by aborted subtransaction must not be visible even if the main transaction +commits. diff --git a/src/backend/access/undo/undoaccess.c b/src/backend/access/undo/undoaccess.c index c215ba1..2d97e7a 100644 --- a/src/backend/access/undo/undoaccess.c +++ b/src/backend/access/undo/undoaccess.c @@ -1013,6 +1013,13 @@ InsertPreparedUndo(UndoRecordInsertContext *context) Assert(bufidx < MAX_BUFFER_PER_UNDO); } while (true); + /* + * Set the current undo location for a transaction. This is required + * to perform rollback during abort of transaction. + */ + SetCurrentUndoLocation(prepared_undo->urp, + context->alloc_context.category); + /* Advance the insert pointer past this record. */ UndoLogAdvanceFinal(prepared_undo->urp, prepared_undo->size); } diff --git a/src/backend/access/undo/undoaction.c b/src/backend/access/undo/undoaction.c index 2c6beae..f521ce9 100644 --- a/src/backend/access/undo/undoaction.c +++ b/src/backend/access/undo/undoaction.c @@ -457,12 +457,30 @@ execute_undo_actions(FullTransactionId full_xid, UndoRecPtr from_urecptr, UndoRecPtr to_urecptr, bool complete_xact) { UndoRecPtr last_log_start_urec_ptr = to_urecptr; + UndoLogCategory logcat = UndoRecPtrGetCategory(to_urecptr); /* 'from' and 'to' pointers must be valid. */ Assert(UndoRecPtrIsValid(from_urecptr)); Assert(UndoRecPtrIsValid(to_urecptr)); /* + * We need to execute the undo actions in a semi-critical section for + * + * (a) Subtransactions. We can't proceed without applying + * subtransaction's undo as the modifications made in that case must not + * be visible even if the main transaction commits. The reason why that + * can happen is because for undo-based AM's we don't need to have a + * separate transaction id for subtransactions and once the main + * transaction commits the tuples modified by subtransactions will become + * visible. + * + * (b) Temp tables. We don't expect background workers to process undo of + * temporary tables as the same won't be accessible. + */ + if (!complete_xact || logcat == UNDO_TEMP) + START_SEMI_CRIT_SECTION(); + + /* * Here we compute the last log start urp which is used for fetching the * undo records and updating the undo action progress. * @@ -472,7 +490,7 @@ execute_undo_actions(FullTransactionId full_xid, UndoRecPtr from_urecptr, */ if (complete_xact) { - if (UndoRecPtrGetCategory(to_urecptr) == UNDO_TEMP) + if (logcat == UNDO_TEMP) { UndoRecPtr end_urec_ptr = from_urecptr; @@ -521,4 +539,7 @@ execute_undo_actions(FullTransactionId full_xid, UndoRecPtr from_urecptr, * Undo actions are applied so delete the hash table entry. */ RollbackHTRemoveEntry(full_xid, to_urecptr, false); + + if (!complete_xact || logcat == UNDO_TEMP) + END_SEMI_CRIT_SECTION(); } diff --git a/src/backend/storage/ipc/ipc.c b/src/backend/storage/ipc/ipc.c index 05d02c2..22f0bac 100644 --- a/src/backend/storage/ipc/ipc.c +++ b/src/backend/storage/ipc/ipc.c @@ -193,6 +193,13 @@ proc_exit_prepare(int code) /* do our shared memory exits first */ shmem_exit(code); + /* + * We need to clear semi-critical-section after exiting from shmem as we + * can again use it for executing undo actions via + * AbortOutOfAnyTransaction which is called during shmem exit. + */ + SemiCritSectionCount = 0; + elog(DEBUG3, "proc_exit(%d): %d callbacks to make", code, on_proc_exit_index); diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index a6505c7..68eaacf 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -594,7 +594,9 @@ ProcessClientWriteInterrupt(bool blocked) * Don't mess with whereToSendOutput if ProcessInterrupts wouldn't * do anything. */ - if (InterruptHoldoffCount == 0 && CritSectionCount == 0) + if (InterruptHoldoffCount == 0 && + CritSectionCount == 0 && + SemiCritSectionCount == 0) { /* * We don't want to send the client the error message, as a) @@ -2985,7 +2987,9 @@ void ProcessInterrupts(void) { /* OK to accept any interrupts now? */ - if (InterruptHoldoffCount != 0 || CritSectionCount != 0) + if (InterruptHoldoffCount != 0 || + CritSectionCount != 0 || + SemiCritSectionCount != 0) return; InterruptPending = false; diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 8b4720e..d24828f 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -259,12 +259,16 @@ errstart(int elevel, const char *filename, int lineno, * 3. the error occurred after proc_exit has begun to run. (It's * proc_exit's responsibility to see that this doesn't turn into * infinite recursion!) + * + * 4. If we are inside a semi-critical section, all errors become FATAL + * errors. See miscadmin.h. */ if (elevel == ERROR) { if (PG_exception_stack == NULL || ExitOnAnyError || - proc_exit_inprogress) + proc_exit_inprogress || + SemiCritSectionCount > 0) elevel = FATAL; } @@ -454,6 +458,7 @@ errfinish(int dummy,...) QueryCancelHoldoffCount = 0; CritSectionCount = 0; /* should be unnecessary, but... */ + SemiCritSectionCount = 0; /* * Note that we leave CurrentMemoryContext set to ErrorContext. The @@ -1165,6 +1170,22 @@ internalerrquery(const char *query) } /* + * err_out_to_client --- sets whether to send error output to client or not. + */ +int +err_out_to_client(bool out_to_client) +{ + ErrorData *edata = &errordata[errordata_stack_depth]; + + /* we don't bother incrementing recursion_depth */ + CHECK_STACK_DEPTH(); + + edata->output_to_client = out_to_client; + + return 0; /* return value does not matter */ +} + +/* * err_generic_string -- used to set individual ErrorData string fields * identified by PG_DIAG_xxx codes. * diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c index 3bf96de..9faeb84 100644 --- a/src/backend/utils/init/globals.c +++ b/src/backend/utils/init/globals.c @@ -36,6 +36,7 @@ volatile sig_atomic_t ConfigReloadPending = false; volatile uint32 InterruptHoldoffCount = 0; volatile uint32 QueryCancelHoldoffCount = 0; volatile uint32 CritSectionCount = 0; +volatile uint32 SemiCritSectionCount = 0; int MyProcPid; pg_time_t MyStartTime; diff --git a/src/backend/utils/resowner/resowner.c b/src/backend/utils/resowner/resowner.c index 7be11c4..7fb8329 100644 --- a/src/backend/utils/resowner/resowner.c +++ b/src/backend/utils/resowner/resowner.c @@ -20,6 +20,7 @@ */ #include "postgres.h" +#include "access/xact.h" #include "jit/jit.h" #include "storage/bufmgr.h" #include "storage/ipc.h" @@ -556,6 +557,11 @@ ResourceOwnerReleaseInternal(ResourceOwner owner, } else if (phase == RESOURCE_RELEASE_LOCKS) { + /* + * For aborts, we don't want to release the locks immediately if we have + * some pending undo actions to perform. Instead, we release them after + * applying undo actions. See ReleaseResourcesAndProcessUndo. + */ if (isTopLevel) { /* @@ -565,7 +571,8 @@ ResourceOwnerReleaseInternal(ResourceOwner owner, */ if (owner == TopTransactionResourceOwner) { - ProcReleaseLocks(isCommit); + if (isCommit || !NeedToPerformUndoActions()) + ProcReleaseLocks(isCommit); ReleasePredicateLocks(isCommit, false); } } @@ -598,7 +605,7 @@ ResourceOwnerReleaseInternal(ResourceOwner owner, if (isCommit) LockReassignCurrentOwner(locks, nlocks); - else + else if (!NeedToPerformUndoActions()) LockReleaseCurrentOwner(locks, nlocks); } } diff --git a/src/include/access/transam.h b/src/include/access/transam.h index 01f248a..7796f72 100644 --- a/src/include/access/transam.h +++ b/src/include/access/transam.h @@ -231,6 +231,7 @@ extern void SetTransactionIdLimit(TransactionId oldest_datfrozenxid, extern void AdvanceOldestClogXid(TransactionId oldest_datfrozenxid); extern bool ForceTransactionIdLimitUpdate(void); extern Oid GetNewObjectId(void); +extern uint32 GetEpochForXid(TransactionId xid); /* * Some frontend programs include this header. For compilers that emit static diff --git a/src/include/access/twophase.h b/src/include/access/twophase.h index b9a531c..497b92f 100644 --- a/src/include/access/twophase.h +++ b/src/include/access/twophase.h @@ -14,6 +14,7 @@ #ifndef TWOPHASE_H #define TWOPHASE_H +#include "access/undolog.h" #include "access/xlogdefs.h" #include "access/xact.h" #include "datatype/timestamp.h" @@ -41,7 +42,7 @@ extern GlobalTransaction MarkAsPreparing(TransactionId xid, const char *gid, TimestampTz prepared_at, Oid owner, Oid databaseid); -extern void StartPrepare(GlobalTransaction gxact); +extern void StartPrepare(GlobalTransaction gxact, UndoRecPtr *, UndoRecPtr *); extern void EndPrepare(GlobalTransaction gxact); extern bool StandbyTransactionIdIsPrepared(TransactionId xid); diff --git a/src/include/access/xact.h b/src/include/access/xact.h index a20726a..2ca61ea 100644 --- a/src/include/access/xact.h +++ b/src/include/access/xact.h @@ -14,6 +14,7 @@ #ifndef XACT_H #define XACT_H +#include "access/undolog.h" #include "access/transam.h" #include "access/xlogreader.h" #include "lib/stringinfo.h" @@ -428,6 +429,16 @@ extern XLogRecPtr XactLogAbortRecord(TimestampTz abort_time, const char *twophase_gid); extern void xact_redo(XLogReaderState *record); +/* functions to allow undo execution */ +extern void SetCurrentUndoLocation(UndoRecPtr urec_ptr, + UndoLogCategory category); +extern void ResetUndoActionsInfo(void); +extern bool NeedToPerformUndoActions(void); +extern void ReleaseResourcesAndProcessUndo(void); +extern bool ProcessUndoRequestForEachLogCat(FullTransactionId fxid, Oid dbid, + UndoRecPtr *end_urec_ptr, UndoRecPtr *start_urec_ptr, + bool *undoRequestResgistered, bool isSubTrans); + /* xactdesc.c */ extern void xact_desc(StringInfo buf, XLogReaderState *record); extern const char *xact_identify(uint8 info); diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h index 1afc4d3..5efc7a2 100644 --- a/src/include/miscadmin.h +++ b/src/include/miscadmin.h @@ -74,6 +74,12 @@ * *critical* code should be marked as a critical section! Currently, this * mechanism is only used for XLOG-related code. * + * Similar to the "critical section", we have another mechanism known as + * "semi critical section". It generally has similar behaviour as + * "critical section" with the difference that it causes any ereport(ERROR) to + * become ereport(FATAL). Currently this is used by undo-machinery, but it + * can be used in other places too. + * *****************************************************************************/ /* in globals.c */ @@ -90,6 +96,7 @@ extern PGDLLIMPORT volatile sig_atomic_t ClientConnectionLost; extern PGDLLIMPORT volatile uint32 InterruptHoldoffCount; extern PGDLLIMPORT volatile uint32 QueryCancelHoldoffCount; extern PGDLLIMPORT volatile uint32 CritSectionCount; +extern PGDLLIMPORT volatile uint32 SemiCritSectionCount; /* in tcop/postgres.c */ extern void ProcessInterrupts(void); @@ -137,6 +144,14 @@ do { \ CritSectionCount--; \ } while(0) +#define START_SEMI_CRIT_SECTION() (SemiCritSectionCount++) + +#define END_SEMI_CRIT_SECTION() \ +do { \ + Assert(SemiCritSectionCount > 0); \ + SemiCritSectionCount--; \ +} while(0) + /***************************************************************************** * globals.h -- * diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h index dbfd8ef..ed31351 100644 --- a/src/include/utils/elog.h +++ b/src/include/utils/elog.h @@ -195,6 +195,8 @@ extern int errposition(int cursorpos); extern int internalerrposition(int cursorpos); extern int internalerrquery(const char *query); +extern int err_out_to_client(bool out_to_client); + extern int err_generic_string(int field, const char *str); extern int geterrcode(void); -- 1.8.3.1 [application/octet-stream] 0013-Allow-execution-and-discard-of-undo-by-background-wo.patch (93.3K, ../../CAA4eK1+McY0qGaak0AHyzdgAn+F6dyxcpDwp9ifGg=1WVDadeQ@mail.gmail.com/14-0013-Allow-execution-and-discard-of-undo-by-background-wo.patch) download | inline diff: From c45e82d283e86570b7551f2eb2e57107c0fae921 Mon Sep 17 00:00:00 2001 From: Amit Kapila <[email protected]> Date: Thu, 13 Jun 2019 16:03:49 +0530 Subject: [PATCH 13/13] Allow execution and discard of undo by background workers. Undo launcher is responsible for launching the workers iff there is some work available in one of the work queues and there are more workers available. The worker is launched to handle requests for a particular database. The discard worker is responsible for discarding the undo log of transactions that are committed and all-visible or are rolled-back. It also registers the request for aborted transactions in the work queues. It iterates through all the active logs one-by-one and tries to discard the transactions that are old enough to matter. We don't allow any transaction older than 2^31 to have pending undo actions. Also, we have a hard limit on the number of transactions that can have pending undo which is proportional to pending_undo_queue_size. Amit Kapila, Dilip Kumar and Kuntal Ghosh with inputs from Andres Freund, Robert Haas and Thomas Munro. --- src/backend/access/rmgrdesc/xlogdesc.c | 4 +- src/backend/access/transam/varsup.c | 35 +- src/backend/access/transam/xact.c | 5 + src/backend/access/transam/xlog.c | 29 + src/backend/access/undo/Makefile | 4 +- src/backend/access/undo/README.UndoProcessing | 77 +++ src/backend/access/undo/discardworker.c | 215 +++++++ src/backend/access/undo/undoaccess.c | 58 +- src/backend/access/undo/undodiscard.c | 490 +++++++++++++++ src/backend/access/undo/undolog.c | 2 + src/backend/access/undo/undorequest.c | 205 ++++++- src/backend/access/undo/undoworker.c | 841 ++++++++++++++++++++++++++ src/backend/commands/tablecmds.c | 5 + src/backend/postmaster/bgworker.c | 11 + src/backend/postmaster/pgstat.c | 9 + src/backend/postmaster/postmaster.c | 11 + src/backend/storage/ipc/ipci.c | 6 + src/backend/storage/lmgr/lwlocknames.txt | 1 + src/backend/storage/lmgr/proc.c | 2 + src/backend/utils/misc/guc.c | 22 + src/backend/utils/misc/postgresql.conf.sample | 1 + src/include/access/discardworker.h | 20 + src/include/access/transam.h | 10 + src/include/access/undodiscard.h | 26 + src/include/access/undolog.h | 13 + src/include/access/undoworker.h | 29 + src/include/catalog/pg_control.h | 9 + src/include/nodes/primnodes.h | 3 +- src/include/pgstat.h | 5 +- src/include/postmaster/postmaster.h | 1 + src/include/storage/lwlock.h | 1 + src/include/storage/proc.h | 4 + src/include/storage/procarray.h | 7 +- src/test/regress/expected/sysviews.out | 3 +- 34 files changed, 2131 insertions(+), 33 deletions(-) create mode 100644 src/backend/access/undo/discardworker.c create mode 100644 src/backend/access/undo/undodiscard.c create mode 100644 src/backend/access/undo/undoworker.c create mode 100644 src/include/access/discardworker.h create mode 100644 src/include/access/undodiscard.h create mode 100644 src/include/access/undoworker.h diff --git a/src/backend/access/rmgrdesc/xlogdesc.c b/src/backend/access/rmgrdesc/xlogdesc.c index 33060f3..4b00d7d 100644 --- a/src/backend/access/rmgrdesc/xlogdesc.c +++ b/src/backend/access/rmgrdesc/xlogdesc.c @@ -48,7 +48,8 @@ xlog_desc(StringInfo buf, XLogReaderState *record) "tli %u; prev tli %u; fpw %s; xid %u:%u; oid %u; multi %u; offset %u; " "oldest xid %u in DB %u; oldest multi %u in DB %u; " "oldest/newest commit timestamp xid: %u/%u; " - "oldest running xid %u; %s", + "oldest running xid %u; " + "oldest full xid having unapplied undo " UINT64_FORMAT "; %s", (uint32) (checkpoint->redo >> 32), (uint32) checkpoint->redo, checkpoint->ThisTimeLineID, checkpoint->PrevTimeLineID, @@ -65,6 +66,7 @@ xlog_desc(StringInfo buf, XLogReaderState *record) checkpoint->oldestCommitTsXid, checkpoint->newestCommitTsXid, checkpoint->oldestActiveXid, + U64FromFullTransactionId(checkpoint->oldestFullXidHavingUnappliedUndo), (info == XLOG_CHECKPOINT_SHUTDOWN) ? "shutdown" : "online"); } else if (info == XLOG_NEXTOID) diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c index fd01989..e74155d 100644 --- a/src/backend/access/transam/varsup.c +++ b/src/backend/access/transam/varsup.c @@ -127,14 +127,16 @@ GetNewTransactionId(bool isSubXact) errmsg("database is not accepting commands to avoid wraparound data loss in database \"%s\"", oldest_datname), errhint("Stop the postmaster and vacuum that database in single-user mode.\n" - "You might also need to commit or roll back old prepared transactions, or drop stale replication slots."))); + "You might also need to commit or roll back old prepared transactions, or drop stale replication slots or\n" + "increase max_undo_workers to allow execution of pending undo."))); else ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("database is not accepting commands to avoid wraparound data loss in database with OID %u", oldest_datoid), errhint("Stop the postmaster and vacuum that database in single-user mode.\n" - "You might also need to commit or roll back old prepared transactions, or drop stale replication slots."))); + "You might also need to commit or roll back old prepared transactions, or drop stale replication slots or\n" + "increase max_undo_workers to allow execution of pending undo."))); } else if (TransactionIdFollowsOrEquals(xid, xidWarnLimit)) { @@ -147,14 +149,16 @@ GetNewTransactionId(bool isSubXact) oldest_datname, xidWrapLimit - xid), errhint("To avoid a database shutdown, execute a database-wide VACUUM in that database.\n" - "You might also need to commit or roll back old prepared transactions, or drop stale replication slots."))); + "You might also need to commit or roll back old prepared transactions, or drop stale replication slots or\n" + "increase max_undo_workers to allow execution of pending undo."))); else ereport(WARNING, (errmsg("database with OID %u must be vacuumed within %u transactions", oldest_datoid, xidWrapLimit - xid), errhint("To avoid a database shutdown, execute a database-wide VACUUM in that database.\n" - "You might also need to commit or roll back old prepared transactions, or drop stale replication slots."))); + "You might also need to commit or roll back old prepared transactions, or drop stale replication slots or\n" + "increase max_undo_workers to allow execution of pending undo."))); } /* Re-acquire lock and start over */ @@ -334,10 +338,24 @@ SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Oid oldest_datoid) TransactionId xidStopLimit; TransactionId xidWrapLimit; TransactionId curXid; + TransactionId oldestXidHavingUndo; + FullTransactionId oldestFullXidHavingUndo; Assert(TransactionIdIsNormal(oldest_datfrozenxid)); /* + * To determine the last safe xid that can be allocated, we need to + * consider oldestXidHavingUnapplied Undo because this is the oldest xid + * whose undo is not yet discarded so this is still a valid xid in the + * system. + */ + oldestFullXidHavingUndo = + FullTransactionIdFromU64(pg_atomic_read_u64(&ProcGlobal->oldestFullXidHavingUnappliedUndo)); + oldestXidHavingUndo = XidFromFullTransactionId(oldestFullXidHavingUndo); + if (TransactionIdIsValid(oldestXidHavingUndo)) + oldest_datfrozenxid = Min(oldest_datfrozenxid, oldestXidHavingUndo); + + /* * The place where we actually get into deep trouble is halfway around * from the oldest potentially-existing XID. (This calculation is * probably off by one or two counts, because the special XIDs reduce the @@ -433,6 +451,9 @@ SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Oid oldest_datoid) * Note: it's also possible that get_database_name fails and returns * NULL, for example because the database just got dropped. We'll * still warn, even though the warning might now be unnecessary. + * + * XXX Can we easily distinguish that the problem is due to unapplied + * undo or some old open transactions? */ if (IsTransactionState()) oldest_datname = get_database_name(oldest_datoid); @@ -445,14 +466,16 @@ SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Oid oldest_datoid) oldest_datname, xidWrapLimit - curXid), errhint("To avoid a database shutdown, execute a database-wide VACUUM in that database.\n" - "You might also need to commit or roll back old prepared transactions, or drop stale replication slots."))); + "You might also need to commit or roll back old prepared transactions, or drop stale replication slots, or\n" + "increase max_undo_workers to allow execution of pending undo."))); else ereport(WARNING, (errmsg("database with OID %u must be vacuumed within %u transactions", oldest_datoid, xidWrapLimit - curXid), errhint("To avoid a database shutdown, execute a database-wide VACUUM in that database.\n" - "You might also need to commit or roll back old prepared transactions, or drop stale replication slots."))); + "You might also need to commit or roll back old prepared transactions, or drop stale replication slots, or\n" + "increase max_undo_workers to allow execution of pending undo."))); } } diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index fbbe585..c06436f 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -26,6 +26,7 @@ #include "access/subtrans.h" #include "access/transam.h" #include "access/twophase.h" +#include "access/undodiscard.h" #include "access/undorequest.h" #include "access/xact.h" #include "access/xlog.h" @@ -2273,6 +2274,10 @@ CommitTransaction(void) AtEOXact_ApplyLauncher(true); pgstat_report_xact_timestamp(0); + /* In single user mode, discard all the undo logs, once committed. */ + if (!IsUnderPostmaster) + UndoLogDiscardAll(); + CurrentResourceOwner = NULL; ResourceOwnerDelete(TopTransactionResourceOwner); s->curTransactionOwner = NULL; diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 5dbe485..99e4322 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -5159,6 +5159,7 @@ BootStrapXLOG(void) checkPoint.newestCommitTsXid = InvalidTransactionId; checkPoint.time = (pg_time_t) time(NULL); checkPoint.oldestActiveXid = InvalidTransactionId; + checkPoint.oldestFullXidHavingUnappliedUndo = InvalidFullTransactionId; ShmemVariableCache->nextFullXid = checkPoint.nextFullXid; ShmemVariableCache->nextOid = checkPoint.nextOid; @@ -6622,6 +6623,9 @@ StartupXLOG(void) (errmsg_internal("commit timestamp Xid oldest/newest: %u/%u", checkPoint.oldestCommitTsXid, checkPoint.newestCommitTsXid))); + ereport(DEBUG1, + (errmsg_internal("oldest xid with epoch having undo: " UINT64_FORMAT, + U64FromFullTransactionId(checkPoint.oldestFullXidHavingUnappliedUndo)))); if (!TransactionIdIsNormal(XidFromFullTransactionId(checkPoint.nextFullXid))) ereport(PANIC, (errmsg("invalid next transaction ID"))); @@ -6638,6 +6642,10 @@ StartupXLOG(void) checkPoint.newestCommitTsXid); XLogCtl->ckptFullXid = checkPoint.nextFullXid; + /* Read oldest xid having undo from checkpoint and set in proc global. */ + pg_atomic_write_u64(&ProcGlobal->oldestFullXidHavingUnappliedUndo, + U64FromFullTransactionId(checkPoint.oldestFullXidHavingUnappliedUndo)); + /* * Initialize replication slots, before there's a chance to remove * required resources. @@ -7326,7 +7334,13 @@ StartupXLOG(void) * end-of-recovery steps fail. */ if (InRecovery) + { ResetUnloggedRelations(UNLOGGED_RELATION_INIT); + ResetUndoLogs(UNDO_UNLOGGED); + } + + /* Always reset temporary undo logs. */ + ResetUndoLogs(UNDO_TEMP); /* * We don't need the latch anymore. It's not strictly necessary to disown @@ -8723,6 +8737,10 @@ CreateCheckPoint(int flags) checkPoint.nextOid += ShmemVariableCache->oidCount; LWLockRelease(OidGenLock); + checkPoint.oldestFullXidHavingUnappliedUndo = + FullTransactionIdFromU64(pg_atomic_read_u64(&ProcGlobal->oldestFullXidHavingUnappliedUndo)); + + MultiXactGetCheckptMulti(shutdown, &checkPoint.nextMulti, &checkPoint.nextMultiOffset, @@ -9635,6 +9653,9 @@ xlog_redo(XLogReaderState *record) MultiXactAdvanceOldest(checkPoint.oldestMulti, checkPoint.oldestMultiDB); + pg_atomic_write_u64(&ProcGlobal->oldestFullXidHavingUnappliedUndo, + U64FromFullTransactionId(checkPoint.oldestFullXidHavingUnappliedUndo)); + /* * No need to set oldestClogXid here as well; it'll be set when we * redo an xl_clog_truncate if it changed since initialization. @@ -9692,12 +9713,17 @@ xlog_redo(XLogReaderState *record) /* ControlFile->checkPointCopy always tracks the latest ckpt XID */ ControlFile->checkPointCopy.nextFullXid = checkPoint.nextFullXid; + ControlFile->checkPointCopy.oldestFullXidHavingUnappliedUndo = + checkPoint.oldestFullXidHavingUnappliedUndo; /* Update shared-memory copy of checkpoint XID/epoch */ SpinLockAcquire(&XLogCtl->info_lck); XLogCtl->ckptFullXid = checkPoint.nextFullXid; SpinLockRelease(&XLogCtl->info_lck); + ControlFile->checkPointCopy.oldestFullXidHavingUnappliedUndo = + checkPoint.oldestFullXidHavingUnappliedUndo; + /* * We should've already switched to the new TLI before replaying this * record. @@ -9737,6 +9763,9 @@ xlog_redo(XLogReaderState *record) MultiXactAdvanceNextMXact(checkPoint.nextMulti, checkPoint.nextMultiOffset); + pg_atomic_write_u64(&ProcGlobal->oldestFullXidHavingUnappliedUndo, + U64FromFullTransactionId(checkPoint.oldestFullXidHavingUnappliedUndo)); + /* * NB: This may perform multixact truncation when replaying WAL * generated by an older primary. diff --git a/src/backend/access/undo/Makefile b/src/backend/access/undo/Makefile index 68696bc..b4e7bab 100644 --- a/src/backend/access/undo/Makefile +++ b/src/backend/access/undo/Makefile @@ -12,7 +12,7 @@ subdir = src/backend/access/undo top_builddir = ../../../.. include $(top_builddir)/src/Makefile.global -OBJS = undoaccess.o undoaction.o undoactionxlog.o undolog.o undorecord.o \ - undorequest.o +OBJS = discardworker.o undoaccess.o undoaction.o undoactionxlog.o undodiscard.o \ + undolog.o undorecord.o undorequest.o undoworker.o include $(top_srcdir)/src/backend/common.mk diff --git a/src/backend/access/undo/README.UndoProcessing b/src/backend/access/undo/README.UndoProcessing index e0caf9e..4d6973b 100644 --- a/src/backend/access/undo/README.UndoProcessing +++ b/src/backend/access/undo/README.UndoProcessing @@ -37,3 +37,80 @@ tables are only accessible in the backend that has created them. We can't postpone applying undo actions for subtransactions as the modifications made by aborted subtransaction must not be visible even if the main transaction commits. + +Undo Requests and Undo workers +------------------------------- +To improve the efficiency of the rollbacks, we create three queues and a hash +table for the rollback requests. A Xid based priority queue will allow us to +process the requests of older transactions and help us to move +oldesdXidHavingUnappliedUndo (this is a xid-horizon below which all the +transactions are visible) forward. A size-based queue which will help us to +perform the rollbacks of larger aborts in a timely fashion, so that we don't get +stuck while processing them during discard of the logs. An error queue to hold +the requests for transactions that failed to apply its undo. The rollback hash +table is used to avoid duplicate undo requests by backends and discard worker. +The table must be able to accommodate all active undo requests. The undo +requests must appear in both xid and size requests queues or neither. As of now, +we process the requests from these queues in a round-robin fashion to give equal +priority to all three types of requests. + +Note that, if the request queues are full, then we put backpressure on backends +to complete the requests by themselves. There is an exception to it where when +error queue becomes full, we just mark the request as 'invalid' and continue to +process other requests if any. The discard worker will find this errored +transaction at later point of time and again add it to the request queues. + +We have the hard limit (proportional to the size of the rollback hash table) +for the number of transactions that can have pending undo. This can help us +in computing the value of oldestXidHavingUnappliedUndo and allowing us not to +accumulate pending undo for a long time which will eventually block the +discard of undo. + +In a running system, scanning the rollback hash table will give us the value of +oldestXidHavingUnappliedUndo, however, after startup, we need to once scan all +the undo logs and populate the rollback hash table. After startup, we allow +connections, but don't allow transactions that want to write undo till the +rollback hash table is initialized. + +To process the request, we get the request from one of the queues, search it in +hash table and mark it as in-progress and then remove from the respective queue. +After that, we perform the request which means apply the undo actions and +remove it from the hash table. + +To apply the undo actions, we collect the undo records in bulk and try to +process them together. We ensure to update the transaction's progress at +regular intervals so that after a crash we can skip already applied undo. The +undo apply progress is updated in terms of the number of blocks processed. +Undo apply progress value XACT_APPLY_PROGRESS_COMPLETED indicates that all the +undo is applied, XACT_APPLY_PROGRESS_NOT_STARTED indicates that no undo action +has been applied yet and any other value indicates that we have applied undo +partially and after crash recovery, we need to start processing the undo from +the same location. + +Undo launcher is responsible for launching the workers iff there is some work +available in one of the work queues and there are more workers available. The +worker is launched to handle requests for a particular database. Each undo +worker then starts reading from one of the queues the requests for that +particular database. A worker would peek into each queue for the requests from +a particular database, if it needs to switch a database in less than +undo_worker_quantum ms after starting. Also, if there is no work, it lingers +for UNDO_WORKER_LINGER_MS. This avoids restarting the workers too frequently. + +Discard Worker +--------------- +The discard worker is responsible for discarding the undo log of transactions +that are committed and all-visible or are rolled-back. It also registers the +request for aborted transactions in the work queues. It iterates through all +the active logs one-by-one and try to discard the transactions that are old +enough to matter. + +For transactions that span across multiple logs, the log for committed and +all-visible transactions are discarded separately for each log. This is +possible as the transactions that span across logs have separate transaction +header for each log. For aborted transactions, we try to process the actions +of the entire transaction at one-shot as we need to perform the actions +starting from end location to start location. However, it is possible that the +later portion of the transaction that is overflowed into a separate log can be +processed separately if we encounter the corresponding log first. If we want +we can combine the log for processing in that case as well, but there is no +clear advantage of the same. diff --git a/src/backend/access/undo/discardworker.c b/src/backend/access/undo/discardworker.c new file mode 100644 index 0000000..f324643 --- /dev/null +++ b/src/backend/access/undo/discardworker.c @@ -0,0 +1,215 @@ +/*------------------------------------------------------------------------- + * + * discardworker.c + * The undo discard worker for asynchronous undo management. + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/backend/postmaster/discardworker.c + * + * The main responsibility of the discard worker is to discard the undo log + * of transactions that are committed and all-visible or are rolledback. It + * also registers the request for aborted transactions in the work queues. + * To know more about work queues, see undorequest.c. It iterates through all + * the active logs one-by-one and try to discard the transactions that are old + * enough to matter. + * + * For tranasctions that spans across multiple logs, the log for committed and + * all-visible transactions are discarded seprately for each log. This is + * possible as the transactions that span across logs have separate transaction + * header for each log. For aborted transactions, we try to process the actions + * of entire transaction at one-shot as we need to perform the actions starting + * from end location to start location. However, it is possbile that the later + * portion of transaction that is overflowed into a separate log can be + * processed separately if we encounter the corresponding log first. If we + * want we can combine the log for processing in that case as well, but there + * is no clear advantage of the same. + *------------------------------------------------------------------------- + */ + +#include "postgres.h" +#include <unistd.h> + +#include "access/discardworker.h" +#include "access/undodiscard.h" +#include "miscadmin.h" +#include "pgstat.h" +#include "postmaster/bgworker.h" +#include "storage/ipc.h" +#include "storage/latch.h" +#include "storage/lwlock.h" +#include "storage/proc.h" +#include "storage/procarray.h" +#include "storage/shmem.h" +#include "tcop/tcopprot.h" +#include "utils/guc.h" +#include "utils/resowner.h" + +static void undoworker_sigterm_handler(SIGNAL_ARGS); + +/* minimum and maximum sleep time for discard worker */ +#define MIN_NAPTIME_PER_CYCLE 100L +#define DELAYED_NAPTIME 10 * MIN_NAPTIME_PER_CYCLE +#define MAX_NAPTIME_PER_CYCLE 100 * MIN_NAPTIME_PER_CYCLE + +static volatile sig_atomic_t got_SIGTERM = false; +static bool hibernate = false; +static long wait_time = MIN_NAPTIME_PER_CYCLE; +static bool am_discard_worker = false; + +/* SIGTERM: set flag to exit at next convenient time */ +static void +undoworker_sigterm_handler(SIGNAL_ARGS) +{ + int save_errno = errno; + + got_SIGTERM = true; + + /* Waken anything waiting on the process latch */ + SetLatch(MyLatch); + + errno = save_errno; +} + +/* + * DiscardWorkerRegister -- Register a undo discard worker. + */ +void +DiscardWorkerRegister(void) +{ + BackgroundWorker bgw; + + memset(&bgw, 0, sizeof(bgw)); + bgw.bgw_flags = BGWORKER_SHMEM_ACCESS | + BGWORKER_BACKEND_DATABASE_CONNECTION; + bgw.bgw_start_time = BgWorkerStart_RecoveryFinished; + snprintf(bgw.bgw_name, BGW_MAXLEN, "discard worker"); + sprintf(bgw.bgw_library_name, "postgres"); + sprintf(bgw.bgw_function_name, "DiscardWorkerMain"); + bgw.bgw_restart_time = 5; + bgw.bgw_notify_pid = 0; + bgw.bgw_main_arg = (Datum) 0; + + RegisterBackgroundWorker(&bgw); +} + +/* + * DiscardWorkerMain -- Main loop for the undo discard worker. + */ +void +DiscardWorkerMain(Datum main_arg) +{ + ereport(LOG, + (errmsg("discard worker started"))); + + /* Establish signal handlers. */ + pqsignal(SIGTERM, undoworker_sigterm_handler); + BackgroundWorkerUnblockSignals(); + + am_discard_worker = true; + + /* Make it easy to identify our processes. */ + SetConfigOption("application_name", MyBgworkerEntry->bgw_name, + PGC_USERSET, PGC_S_SESSION); + + /* Establish connection to nailed catalogs. */ + BackgroundWorkerInitializeConnection(NULL, NULL, 0); + + /* + * Scan all the undo logs and intialize the rollback hash table with all + * the pending rollback requests. This need to be done as a first step + * because only after this the transactions will be allowed to write new + * undo. See comments atop UndoLogProcess. + */ + UndoLogProcess(); + + /* Enter main loop */ + while (!got_SIGTERM) + { + TransactionId OldestXmin, + oldestXidHavingUndo; + FullTransactionId oldestFullXidHavingUndo; + int rc; + + /* + * It is okay to ignore vacuum transaction here, as we can discard the + * undo of the vacuuming transaction if the transaction is committed. + * We don't need to hold its undo for the visibility purpose. + */ + OldestXmin = GetOldestXmin(NULL, PROCARRAY_FLAGS_AUTOVACUUM | + PROCARRAY_FLAGS_VACUUM); + + oldestFullXidHavingUndo = + FullTransactionIdFromU64(pg_atomic_read_u64(&ProcGlobal->oldestFullXidHavingUnappliedUndo)); + oldestXidHavingUndo = XidFromFullTransactionId(oldestFullXidHavingUndo); + + /* + * Call the discard routine if oldestXidHavingUndo is lagging behind + * OldestXmin. + */ + if (OldestXmin != InvalidTransactionId && + TransactionIdPrecedes(oldestXidHavingUndo, OldestXmin)) + { + UndoDiscard(OldestXmin, &hibernate); + + /* + * If we got some undo logs to discard or discarded something, + * then reset the wait_time as we have got work to do. Note that + * if there are some undologs that cannot be discarded, then above + * condition will remain unsatisfied till oldestXmin remains + * unchanged and the wait_time will not reset in that case. + */ + if (!hibernate) + wait_time = MIN_NAPTIME_PER_CYCLE; + } + + /* Wait for more work. */ + rc = WaitLatch(&MyProc->procLatch, + WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH, + wait_time, + WAIT_EVENT_UNDO_DISCARD_WORKER_MAIN); + + if (rc & WL_LATCH_SET) + { + ResetLatch(&MyProc->procLatch); + CHECK_FOR_INTERRUPTS(); + } + + /* + * Increase the wait_time based on the length of inactivity. If + * wait_time is within one second, then increment it by 100 ms at a + * time. Henceforth, increment it one second at a time, till it + * reaches ten seconds. Never increase the wait_time more than ten + * seconds, it will be too much of waiting otherwise. + */ + if (rc & WL_TIMEOUT && hibernate) + { + wait_time += (wait_time < DELAYED_NAPTIME ? + MIN_NAPTIME_PER_CYCLE : DELAYED_NAPTIME); + if (wait_time > MAX_NAPTIME_PER_CYCLE) + wait_time = MAX_NAPTIME_PER_CYCLE; + } + + /* emergency bailout if postmaster has died */ + if (rc & WL_POSTMASTER_DEATH) + proc_exit(1); + } + + /* Normal exit from discard worker */ + ereport(LOG, + (errmsg("discard worker shutting down"))); + + proc_exit(0); +} + +/* + * IsDiscardProcess -- Tells whether the current process is a discard worker + * process. + */ +bool +IsDiscardProcess(void) +{ + return am_discard_worker; +} diff --git a/src/backend/access/undo/undoaccess.c b/src/backend/access/undo/undoaccess.c index 2d97e7a..9faae13 100644 --- a/src/backend/access/undo/undoaccess.c +++ b/src/backend/access/undo/undoaccess.c @@ -56,6 +56,7 @@ #include "storage/buf.h" #include "storage/buf_internals.h" #include "storage/bufmgr.h" +#include "storage/proc.h" #include "miscadmin.h" /* @@ -77,6 +78,13 @@ */ UndoCompressionInfo undo_compression_info[UndoLogCategories]; +/* + * Defines the number of times we try to wait for rollback hash table to get + * initialized. After these many attempts it will return error and the user + * can retry the operation. + */ +#define ROLLBACK_HT_INIT_WAIT_TRY 60 + /* Prototypes for static functions. */ static UnpackedUndoRecord *UndoGetOneRecord(UnpackedUndoRecord *urec, UndoRecPtr urp, RelFileNode rnode, @@ -672,6 +680,50 @@ PrepareUndoInsert(UndoRecordInsertContext *context, UndoCompressionInfo *compression_info = &context->undo_compression_info[context->alloc_context.category]; + if (!InRecovery && IsUnderPostmaster) + { + int try_count = 0; + + /* + * If we are not in a recovery and not in a single-user-mode, then undo + * generation should not be allowed until we have scanned all the undo + * logs and initialized the hash table with all the aborted + * transaction entries. See detailed comments in UndoLogProcess. + */ + while (!ProcGlobal->rollbackHTInitialized) + { + /* Error out after trying for one minute. */ + if (try_count > ROLLBACK_HT_INIT_WAIT_TRY) + ereport(ERROR, + (errcode(ERRCODE_E_R_E_MODIFYING_SQL_DATA_NOT_PERMITTED), + errmsg("rollback hash table is not yet initialized, wait for sometime and try again"))); + + /* + * Rollback hash table is not yet intialized, sleep for 1 second + * and try again. + */ + pg_usleep(1000000L); + try_count++; + } + } + + /* + * If the rollback hash table is already full (excluding one additional + * space for each backend) then don't allow to generate any new undo until + * we apply some of the pending requests and create some space in the hash + * table to accept new rollback requests. Leave the enough slots in the + * hash table so that there is space for all the backends to register at + * least one request. This is to protect the situation where one backend + * keep consuming slots reserve for the other backends and suddenly there + * is concurrent undo request from all the backends. So we always keep + * the space reserve for MaxBackends. + */ + if (ProcGlobal->xactsHavingPendingUndo > + (UndoRollbackHashTableSize() - MaxBackends)) + ereport(ERROR, + (errcode(ERRCODE_INSUFFICIENT_RESOURCES), + errmsg("max limit for pending rollback request has reached, wait for sometime and try again"))); + /* Already reached maximum prepared limit. */ if (context->nprepared_undo == context->max_prepared_undo) elog(ERROR, "already reached the maximum prepared limit"); @@ -1828,12 +1880,12 @@ UndoBlockGetFirstUndoRecord(BlockNumber blkno, UndoRecPtr urec_ptr, LockBuffer(buffer, BUFFER_LOCK_SHARE); page = BufferGetPage(buffer); - phdr = (UndoPageHeader)page; + phdr = (UndoPageHeader) page; /* Calculate the size of the partial record. */ partial_rec_size = UndoRecordHeaderSize(phdr->uur_info) + - phdr->tuple_len + phdr->payload_len - - phdr->record_offset; + phdr->tuple_len + phdr->payload_len - + phdr->record_offset; /* calculate the offset in current log. */ offset_cur_page = SizeOfUndoPageHeaderData + partial_rec_size; diff --git a/src/backend/access/undo/undodiscard.c b/src/backend/access/undo/undodiscard.c new file mode 100644 index 0000000..dfabbfa --- /dev/null +++ b/src/backend/access/undo/undodiscard.c @@ -0,0 +1,490 @@ +/*------------------------------------------------------------------------- + * + * undodiscard.c + * discard undo records + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/backend/access/undo/undodiscard.c + * + *------------------------------------------------------------------------- + */ + +#include "postgres.h" + +#include "access/undodiscard.h" +#include "access/undolog.h" +#include "access/undorequest.h" +#include "access/xact.h" +#include "access/xlog.h" +#include "access/xlog_internal.h" +#include "catalog/pg_tablespace.h" +#include "miscadmin.h" +#include "storage/block.h" +#include "storage/buf.h" +#include "storage/bufmgr.h" +#include "storage/proc.h" +#include "storage/procarray.h" +#include "storage/shmem.h" + +/* + * Discard as many record sets as we can from the undo log occupying a given + * slot, considering the given xmin horizon. If we encounter a record set + * that needs to be rolled back, register a rollback request. Set *hibernate + * to false if work was done. + */ +static void +UndoDiscardOneLog(UndoLogSlot *slot, TransactionId xmin, bool *hibernate) +{ + UndoRecPtr undo_recptr; + UndoRecPtr next_urecptr = InvalidUndoRecPtr; + bool need_discard = false; + TransactionId latest_discardxid = InvalidTransactionId; + UndoLogNumber logno; + + /* + * Currently we expect only one discard worker to be active at any time, + * but in future we might have more than one, and superuser maintenance + * functions might also discard data concurrently. So we we have to + * assume that the given slot could be recycled underneath us any time we + * don't hold one of the locks that prevents that. We'll detect that by + * the log number changing. + */ + LWLockAcquire(&slot->discard_lock, LW_SHARED); + logno = slot->logno; + if (UndoRecPtrIsValid(slot->oldest_data)) + { + undo_recptr = slot->oldest_data; + LWLockRelease(&slot->discard_lock); + } + else + { + LWLockRelease(&slot->discard_lock); + undo_recptr = UndoLogGetOldestRecord(logno, NULL); + } + + /* There might not be any undo log and hibernation might be needed. */ + *hibernate = true; + + StartTransactionCommand(); + + /* Loop until we run out of discardable transactions in the given log. */ + do + { + UnpackedUndoRecord *uur = NULL; + UndoRecPtr next_insert; + FullTransactionId undofxid = InvalidFullTransactionId; + TransactionId wait_xid = InvalidTransactionId; + bool pending_abort = false; + bool request_rollback = false; + UndoStatus status; + UndoRecordFetchContext context; + + next_insert = UndoLogGetNextInsertPtr(logno); + + /* There must be some undo data for a transaction. */ + Assert(next_insert != undo_recptr); + + /* Fetch the undo record for the given undo_recptr. */ + BeginUndoFetch(&context); + uur = UndoFetchRecord(&context, undo_recptr); + FinishUndoFetch(&context); + + if (uur != NULL) + { + if (UndoRecPtrGetCategory(undo_recptr) == UNDO_SHARED) + { + /* + * For the "shared" category, we only discard when the + * rm_undo_status callback tells us we can. + */ + status = RmgrTable[uur->uur_rmid].rm_undo_status(uur, &wait_xid); + + Assert((status == UNDO_STATUS_WAIT_XMIN && + TransactionIdIsValid(wait_xid)) ^ + (status == UNDO_STATUS_DISCARD && + !TransactionIdIsValid(wait_xid))); + } + else + { + TransactionId xid = XidFromFullTransactionId(uur->uur_fxid); + + /* + * Otherwise we use the CLOG and xmin to decide whether to + * wait, discard or roll back. + * + * XXX: We've added the transaction-in-progress check to + * avoid xids of in-progress autovacuum as those are not + * computed for oldestxmin calculation. See + * DiscardWorkerMain. + */ + if (TransactionIdDidCommit(xid)) + { + /* + * If this record set's xid isn't before the xmin + * horizon, we'll have to wait before we can discard + * it. + */ + if (TransactionIdFollowsOrEquals(xid, xmin)) + wait_xid = xid; + + } + else if (!TransactionIdIsInProgress(xid)) + { + /* + * If it hasn't been applied already, then we'll ask + * for it to be applied now. Otherwise it'll be + * discarded. + */ + if (!IsXactApplyProgressCompleted(uur->uur_txn->urec_progress)) + request_rollback = true; + } + else + { + /* + * It's either in progress or isn't yet before the + * xmin horizon, so we'll have to wait. + */ + wait_xid = XidFromFullTransactionId(uur->uur_fxid); + } + } + + /* + * Add the aborted transaction to the rollback request queues. + * + * We can ignore the abort for transactions whose corresponding + * database doesn't exist. + */ + if (request_rollback && dbid_exists(uur->uur_txn->urec_dbid)) + { + (void) RegisterUndoRequest(InvalidUndoRecPtr, + undo_recptr, + uur->uur_txn->urec_dbid, + uur->uur_fxid); + + pending_abort = true; + } + + next_urecptr = uur->uur_txn->urec_next; + undofxid = uur->uur_fxid; + + UndoRecordRelease(uur); + uur = NULL; + } + + /* + * We can discard upto this point when one of following conditions is + * met: (a) we need to wait for a transaction first. (b) there is no + * more log to process. (c) the transaction undo in current log is + * finished. (d) there is a pending abort. + */ + if (TransactionIdIsValid(wait_xid) || + next_urecptr == InvalidUndoRecPtr || + UndoRecPtrGetLogNo(next_urecptr) != logno || + pending_abort) + { + /* Hey, I got some undo log to discard, can not hibernate now. */ + *hibernate = false; + + /* + * If we don't need to wait for this transaction and this is not + * an aborted transaction, then we can discard it as well. + */ + if (!TransactionIdIsValid(wait_xid) && !pending_abort) + { + /* + * It is safe to use next_insert as the location till which we + * want to discard in this case. If something new has been + * added after we have fetched this transaction's record, it + * won't be considered in this pass of discard. + */ + undo_recptr = next_insert; + latest_discardxid = XidFromFullTransactionId(undofxid); + need_discard = true; + + /* We don't have anything more to discard. */ + undofxid = InvalidFullTransactionId; + } + + /* Update the shared memory state. */ + LWLockAcquire(&slot->discard_lock, LW_EXCLUSIVE); + + /* + * If the slot has been recycling while we were thinking about it, + * we have to abandon the operation. + */ + if (slot->logno != logno) + { + LWLockRelease(&slot->discard_lock); + break; + } + + /* Update the slot information for the next pass of discard. */ + slot->wait_fxmin = undofxid; + slot->oldest_data = undo_recptr; + + LWLockRelease(&slot->discard_lock); + + if (need_discard) + { + LWLockAcquire(&slot->discard_update_lock, LW_EXCLUSIVE); + UndoLogDiscard(undo_recptr, latest_discardxid); + LWLockRelease(&slot->discard_update_lock); + } + + break; + } + + /* + * This transaction is smaller than the xmin so lets jump to the next + * transaction. + */ + undo_recptr = next_urecptr; + latest_discardxid = XidFromFullTransactionId(undofxid); + + /* The fetched undo record must be release by now. */ + Assert(uur == NULL); + + /* If we reach here, this means there is something to discard. */ + need_discard = true; + } while (true); + + CommitTransactionCommand(); +} + +/* + * Scan all the undo logs and register the aborted transactions. This is + * called as a first function from the discard worker and only after this pass + * over undo logs is complete, new undo is allowed to be written in the + * system. This is required because after crash recovery we don't know the + * exact number of aborted transactions whose rollback request is pending and + * we can not allow new undo request if we already have the request equal to + * hash table size. So before allowing any new transaction to start writing + * the undo we need to make sure that we know exact number of pending + * requests. + */ +void +UndoLogProcess() +{ + UndoLogSlot *slot = NULL; + + /* + * We need to perform this in a transaction because (a) we need resource + * owner to scan the logs and (b) TransactionIdIsInProgress requires us to + * be in transaction. + */ + StartTransactionCommand(); + + /* + * Loop through all the valid undo logs and scan them transaction by + * transaction to find non-commited transactions if any and register them + * in the rollback hash table. + */ + while ((slot = UndoLogNextSlot(slot))) + { + UndoRecPtr undo_recptr; + UnpackedUndoRecord *uur = NULL; + + /* We do not execute shared (non-transactional) undo records. */ + if (slot->meta.category == UNDO_SHARED) + continue; + + /* Start scanning the log from the last discard point. */ + undo_recptr = UndoLogGetOldestRecord(slot->logno, NULL); + + /* Loop until we scan complete log. */ + while (1) + { + TransactionId xid; + UndoRecordFetchContext context; + + /* Done with this log. */ + if (!UndoRecPtrIsValid(undo_recptr)) + break; + + /* Fetch the undo record for the given undo_recptr. */ + BeginUndoFetch(&context); + uur = UndoFetchRecord(&context, undo_recptr); + FinishUndoFetch(&context); + + Assert(uur != NULL); + + xid = XidFromFullTransactionId(uur->uur_fxid); + + /* + * Register the rollback request for all uncommitted and not in + * progress transactions whose undo apply progress is still not + * completed. Even though we don't allow any new transactions to + * write undo until this first pass is completed, there might be + * some prepared transactions which are still in progress, so we + * don't include such transactions. + */ + if (!TransactionIdDidCommit(xid) && + !TransactionIdIsInProgress(xid) && + !IsXactApplyProgressCompleted(uur->uur_txn->urec_progress)) + { + (void) RegisterUndoRequest(InvalidUndoRecPtr, undo_recptr, + uur->uur_txn->urec_dbid, + uur->uur_fxid); + } + + /* + * Go to the next transaction in the same log. If uur_next is + * point to the undo record pointer in the different log then we are + * done with this log so just set undo_recptr to InvalidUndoRecPtr. + */ + if (UndoRecPtrGetLogNo(undo_recptr) == + UndoRecPtrGetLogNo(uur->uur_txn->urec_next)) + undo_recptr = uur->uur_txn->urec_next; + else + undo_recptr = InvalidUndoRecPtr; + + /* Release memory for the current record. */ + UndoRecordRelease(uur); + } + } + + CommitTransactionCommand(); + + /* Allow the transactions to start writting undo. */ + ProcGlobal->rollbackHTInitialized = true; +} + +/* + * Discard the undo for all the transactions whose xid is smaller than + * oldestXmin + */ +void +UndoDiscard(TransactionId oldestXmin, bool *hibernate) +{ + FullTransactionId oldestXidHavingUndo; + UndoLogSlot *slot = NULL; + uint32 epoch; + + /* + * If all the undo logs are discarded, then oldestXidHavingUndo should be + * oldestXmin. As of now, we don't allow more than 2 billion xids in the + * system, so we can rely on the epoch retrieved with GetEpochForXid. + */ + epoch = GetEpochForXid(oldestXmin); + oldestXidHavingUndo = FullTransactionIdFromEpochAndXid(epoch, oldestXmin); + + /* + * Iterate through all the active logs and one-by-one try to discard the + * transactions that are old enough to matter. + * + * XXX Ideally we can arrange undo logs so that we can efficiently find + * those with oldest_xid < oldestXmin, but for now we'll just scan all of + * them. + */ + while ((slot = UndoLogNextSlot(slot))) + { + /* + * If the log is already discarded, then we are done. It is important + * to first check this to ensure that tablespace containing this log + * doesn't get dropped concurrently. + * + * We don't have to worry about slot recycling and check the logno + * here, since we don't care about the identity of this slot, we're + * visiting all of them. + */ + LWLockAcquire(&slot->mutex, LW_SHARED); + if (slot->meta.discard == slot->meta.unlogged.insert) + { + LWLockRelease(&slot->mutex); + continue; + } + LWLockRelease(&slot->mutex); + + /* We can't process temporary undo logs. */ + if (slot->meta.category == UNDO_TEMP) + continue; + + /* + * If the first xid of the undo log is smaller than the xmin then try + * to discard the undo log. + */ + if (!FullTransactionIdIsValid(slot->wait_fxmin) || + FullTransactionIdPrecedes(slot->wait_fxmin, oldestXidHavingUndo)) + { + /* Process the undo log. */ + UndoDiscardOneLog(slot, oldestXmin, hibernate); + } + } + + /* Get the smallest of 'xid having pending undo' and 'oldestXmin' */ + oldestXidHavingUndo = RollbackHTGetOldestFullXid(oldestXidHavingUndo); + + /* + * Update the oldestFullXidHavingUnappliedUndo in the shared memory. + * + * XXX: In future, if multiple workers can perform discard then we may + * need to use compare and swap for updating the shared memory value. + */ + Assert(FullTransactionIdIsValid(oldestXidHavingUndo)); + pg_atomic_write_u64(&ProcGlobal->oldestFullXidHavingUnappliedUndo, + U64FromFullTransactionId(oldestXidHavingUndo)); +} + +/* + * Discard all the logs. This is particularly required in single user mode + * where at the commit time we discard all the undo logs. + */ +void +UndoLogDiscardAll(void) +{ + UndoLogSlot *slot = NULL; + + Assert(!IsUnderPostmaster); + + /* + * No locks are required for discard, since this called only in single + * user mode. + */ + while ((slot = UndoLogNextSlot(slot))) + { + /* If the log is already discarded, then we are done. */ + if (slot->meta.discard == slot->meta.unlogged.insert) + continue; + + /* + * Process the undo log. + */ + UndoLogDiscard(MakeUndoRecPtr(slot->logno, slot->meta.unlogged.insert), + InvalidTransactionId); + } + +} + +/* + * Discard the undo logs for temp tables. + */ +void +TempUndoDiscard(UndoLogNumber logno) +{ + UndoLogSlot *slot = UndoLogGetSlot(logno, false); + + /* + * Discard the undo log for temp table only. Ensure that there is + * something to be discarded there. + */ + Assert (slot->meta.category == UNDO_TEMP); + + /* + * If the log is already discarded, then we are done. It is important + * to first check this to ensure that tablespace containing this log + * doesn't get dropped concurrently. + */ + LWLockAcquire(&slot->mutex, LW_SHARED); + if (slot->meta.discard == slot->meta.unlogged.insert) + { + LWLockRelease(&slot->mutex); + return; + } + LWLockRelease(&slot->mutex); + + /* Process the undo log. */ + UndoLogDiscard(MakeUndoRecPtr(slot->logno, slot->meta.unlogged.insert), + InvalidTransactionId); +} diff --git a/src/backend/access/undo/undolog.c b/src/backend/access/undo/undolog.c index b5502f2..09d9b30 100644 --- a/src/backend/access/undo/undolog.c +++ b/src/backend/access/undo/undolog.c @@ -145,6 +145,8 @@ UndoLogShmemInit(void) LWTRANCHE_UNDOLOG); LWLockInitialize(&UndoLogShared->slots[i].discard_lock, LWTRANCHE_UNDODISCARD); + LWLockInitialize(&UndoLogShared->slots[i].discard_update_lock, + LWTRANCHE_DISCARD_UPDATE); } } else diff --git a/src/backend/access/undo/undorequest.c b/src/backend/access/undo/undorequest.c index 530887a..0222c86 100644 --- a/src/backend/access/undo/undorequest.c +++ b/src/backend/access/undo/undorequest.c @@ -54,10 +54,12 @@ #include "postgres.h" #include "miscadmin.h" +#include "access/discardworker.h" #include "access/genam.h" #include "access/heapam.h" #include "access/transam.h" #include "access/undorequest.h" +#include "access/undoworker.h" #include "access/xact.h" #include "catalog/indexing.h" #include "catalog/pg_database.h" @@ -880,9 +882,6 @@ FindUndoEndLocationAndSize(UndoRecPtr start_urecptr, */ if (UndoRecPtrIsDiscarded(next_urecptr)) { - UndoLogOffset next_insert; - - next_insert = UndoLogGetNextInsertPtr(slot->logno); Assert(UndoRecPtrIsValid(next_insert)); last_log_start_urecptr = urecptr; @@ -898,9 +897,6 @@ FindUndoEndLocationAndSize(UndoRecPtr start_urecptr, * this log for request size computation. */ { - UndoLogOffset next_insert; - - next_insert = UndoLogGetNextInsertPtr(slot->logno); Assert(UndoRecPtrIsValid(next_insert)); last_log_start_urecptr = urecptr; @@ -928,6 +924,138 @@ FindUndoEndLocationAndSize(UndoRecPtr start_urecptr, } /* + * Fetch the start urec pointer for the transaction and the undo request size. + * + * start_urecptr_inout - This is an INOUT parameter. If a transaction has + * overflowed to multiple undo logs, the caller can set start_urecptr_inout + * to a location of any of the undo logs where the transaction has written its + * first record for that particular log. Given that, this function calculates + * the undo location where the transaction has inserted its first undo record. + * If a transaction hasn't overflowed to multiple undo logs, the value of this + * parameter remains unchanged. + * + * The first record of a transaction in each undo log contains a reference to + * the first record of this transaction in the previous log. It finds the + * initial location by moving backward in the undo chain of this transaction + * across undo logs. While doing the same, it also calculates the undo size + * between the input and output start undo record pointer value. + */ +static uint64 +FindUndoStartLocationAndSize(UndoRecPtr *start_urecptr_inout, + FullTransactionId full_xid) +{ + UnpackedUndoRecord *uur = NULL; + UndoLogSlot *slot = NULL; + UndoRecPtr urecptr = InvalidUndoRecPtr; + uint64 sz = 0; + + Assert(start_urecptr_inout); + + urecptr = *start_urecptr_inout; + Assert(urecptr != InvalidUndoRecPtr); + + /* + * A backend always set the start undo record pointer to the first undo + * record inserted by this transaction. Hence, we don't have to proceed + * further. + */ + if (!IsDiscardProcess()) + return sz; + + /* + * Since the discard worker processes the undo logs sequentially, it's + * possible that start undo record pointer doesn't refer to the actual + * start of the transaction. Instead, it may refer to the start location + * of the transaction in any of the subsequent logs. In that case, we've + * to find the actual start location of the transaction by going backwards + * in the chain. + */ + while (true) + { + UndoLogOffset next_insert; + UndoRecordFetchContext context; + + /* + * Fetch the log and undo record corresponding to the current undo + * pointer. + */ + if ((slot == NULL) || (UndoRecPtrGetLogNo(urecptr) != slot->logno)) + slot = UndoLogGetSlot(UndoRecPtrGetLogNo(urecptr), false); + + Assert(slot != NULL); + + /* The corresponding log must be ahead urecptr. */ + Assert(MakeUndoRecPtr(slot->logno, slot->meta.unlogged.insert) >= urecptr); + + /* Fetch the undo record. */ + BeginUndoFetch(&context); + uur = UndoFetchRecord(&context, urecptr); + FinishUndoFetch(&context); + + /* + * Since the rollback isn't completed for this transaction, this undo + * record can't be discarded. + */ + Assert (uur != NULL); + + /* The undo must belongs to a same transaction. */ + Assert(FullTransactionIdEquals(full_xid, uur->uur_fxid)); + + /* + * Since this is the first undo record of this transaction in this + * log, this must include the transaction header. + */ + Assert(uur->uur_info & UREC_INFO_TRANSACTION); + + /* + * If this is the first undo record of this transaction, return from + * here. + */ + if ((uur->uur_info & UREC_INFO_LOGSWITCH) == 0) + { + UndoRecordRelease(uur); + break; + } + + /* + * This is a start of a overflowed transaction header, so it must have + * a valid pointer to previous log's start transaction header. + */ + Assert(UndoRecPtrIsValid(uur->uur_logswitch->urec_prevlogstart)); + + + /* + * Find the previous log from which the transaction is overflowed + * to current log. + */ + urecptr = uur->uur_logswitch->urec_prevlogstart; + slot = UndoLogGetSlot(UndoRecPtrGetLogNo(urecptr), false); + + /* + * When a transaction overflows to a new undo log, it's guaranteed + * that this transaction will be the last transaction in the previous + * log and we mark that log as full so that no other transaction can + * write in that log further. Check UndoLogAllocate for details. + * + * So, to find the undo size in the previous log, we've to find the + * next insert location of the previous log and subtract current + * transaction's start location in the previous log from it. + */ + next_insert = UndoLogGetNextInsertPtr(slot->logno); + Assert(UndoRecPtrIsValid(next_insert)); + + sz += (next_insert - urecptr); + + UndoRecordRelease(uur); + uur = NULL; + } + + *start_urecptr_inout = urecptr; + + return sz; +} + +/* * Returns true, if we can push the rollback request to undo wrokers, false, * otherwise. */ @@ -943,9 +1071,24 @@ CanPushReqToUndoWorker(UndoRecPtr start_urec_ptr, UndoRecPtr end_urec_ptr, /* * We normally push the rollback request to undo workers if the size of - * same is above a certain threshold. + * same is above a certain threshold. However, discard worker is allowed + * to push any size request provided there is a space in rollback request + * queue. This is mainly because discard worker can be processing the + * rollback requests after crash recovery when no backend is alive. + * + * We have a race condition where discard worker can process the request + * before the backend which has aborted the transaction in which case + * backend won't do anything. Normally, this won't happen because + * backends try to apply the undo actions immediately after marking the + * transaction as aborted in the clog. One way to avoid this race + * condition is that we register the request by backend in hash table but + * not in rollback queues before marking abort in clog and then later add + * them in rollback queues. However, we are not sure how important it is + * avoid such a race as this won't lead to any problem and OTOH, we might + * need some more trickery in the code to avoid such a race condition. */ - if (req_size >= rollback_overflow_size * 1024 * 1024) + if (req_size >= rollback_overflow_size * 1024 * 1024 || + IsDiscardProcess()) { if (GetXidQueueSize() >= pending_undo_queue_size || GetSizeQueueSize() >= pending_undo_queue_size) @@ -971,12 +1114,7 @@ CanPushReqToUndoWorker(UndoRecPtr start_urec_ptr, UndoRecPtr end_urec_ptr, if ((GetXidQueueSize() < pending_undo_queue_size)) { Assert(GetSizeQueueSize() < pending_undo_queue_size); - - /* - * XXX - Here, we should return true once we have background - * worker facility. - */ - return false; + return true; } } @@ -1417,6 +1555,12 @@ RegisterUndoRequest(UndoRecPtr end_urec_ptr, UndoRecPtr start_urec_ptr, Assert(dbid != InvalidOid); /* + * The discard worker can only send the start undo record pointer of a + * transaction. It doesn't set the end_urec_ptr. + */ + Assert(IsDiscardProcess() || UndoRecPtrIsValid(end_urec_ptr)); + + /* * Find the rollback request size and the end_urec_ptr (in case of discard * worker only). */ @@ -1431,6 +1575,14 @@ RegisterUndoRequest(UndoRecPtr end_urec_ptr, UndoRecPtr start_urec_ptr, if (!UndoRecPtrIsValid(end_urec_ptr)) return false; + /* + * For registering a rollback request, we always store the full transaction + * ID and the first undo record pointer inserted by this transaction. This + * ensures that backends and discard worker don't register the same request + * twice. + */ + req_size += FindUndoStartLocationAndSize(&start_urec_ptr, full_xid); + LWLockAcquire(RollbackRequestLock, LW_EXCLUSIVE); /* @@ -1446,7 +1598,13 @@ RegisterUndoRequest(UndoRecPtr end_urec_ptr, UndoRecPtr start_urec_ptr, HASH_ENTER_NULL, &found); /* - * It can only fail, if the value of pending_undo_queue_size or + * Except the first pass over the undo logs by discard worker, the hash + * table can never be full. + */ + Assert(!ProcGlobal->rollbackHTInitialized || (rh != NULL)); + + /* + * It can only fail, if the value of pending_undo_queue_size or * max_connections guc is reduced after restart of the server. */ if (rh == NULL) @@ -1494,10 +1652,16 @@ RegisterUndoRequest(UndoRecPtr end_urec_ptr, UndoRecPtr start_urec_ptr, } /* * The request can't be pushed into the undo worker queue. The - * backends will try executing by itself. + * backends will try executing by itself. The discard worker will + * keep the entry into the rollback hash table with + * UNDO_REQUEST_INVALID status. Such requests will be added in the + * undo worker queues in the subsequent passes over undo logs by + * discard worker. */ - else + else if (!IsDiscardProcess()) rh->status = UNDO_REQUEST_INPROGRESS; + else + rh->status = UNDO_REQUEST_INVALID; } else if (!UndoRequestIsValid(rh) && can_push) { @@ -1525,6 +1689,13 @@ RegisterUndoRequest(UndoRecPtr end_urec_ptr, UndoRecPtr start_urec_ptr, LWLockRelease(RollbackRequestLock); + /* + * If we are able to successfully push the request, wakeup the undo worker + * so that it can be processed in a timely fashion. + */ + if (pushed) + WakeupUndoWorker(dbid); + return pushed; } diff --git a/src/backend/access/undo/undoworker.c b/src/backend/access/undo/undoworker.c new file mode 100644 index 0000000..3741445 --- /dev/null +++ b/src/backend/access/undo/undoworker.c @@ -0,0 +1,841 @@ +/*------------------------------------------------------------------------- + * + * undoworker.c + * undo launcher and undo worker process. + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/backend/postmaster/undoworker.c + * + * Undo launcher is responsible for launching the workers iff there is some + * work available in one of work queues and there are more workers available. + * To know more about work queues, see undorequest.c. The worker is launched + * to handle requests for a particular database. + * + * Each undo worker then starts reading from one of the queues the requests + * for that particular database. A worker would peek into each queue for the + * requests from a particular database, if it needs to switch a database in + * less than undo_worker_quantum ms after starting. Also, if there is no + * work, it lingers for UNDO_WORKER_LINGER_MS. This avoids restarting + * the workers too frequently. + *------------------------------------------------------------------------- + */ + +#include "postgres.h" + +#include "access/genam.h" +#include "access/table.h" +#include "access/undorequest.h" +#include "access/undoworker.h" +#include "access/xact.h" +#include "funcapi.h" +#include "libpq/pqsignal.h" +#include "miscadmin.h" +#include "pgstat.h" +#include "postmaster/bgworker.h" +#include "postmaster/fork_process.h" +#include "postmaster/postmaster.h" +#include "replication/slot.h" +#include "replication/worker_internal.h" +#include "storage/ipc.h" +#include "storage/lmgr.h" +#include "storage/proc.h" +#include "storage/procarray.h" +#include "storage/procsignal.h" +#include "tcop/tcopprot.h" +#include "utils/hsearch.h" +#include "utils/memutils.h" +#include "utils/resowner.h" + + +/* + * GUC parameters + */ +int max_undo_workers = 4; + +/* + * If a worker would need to switch databases in less than undo_worker_quantum + * (10s as default) after starting, it peeks a few entries deep into each + * queue to see whether there's work for that database. + */ +int undo_worker_quantum_ms = 10000; + +/* max sleep time between cycles (100 milliseconds) */ +#define DEFAULT_NAPTIME_PER_CYCLE 100L + +/* + * Time for which undo worker can linger if there is no work, in + * milliseconds. This has to be more than UNDO_FAILURE_RETRY_DELAY_MS, + * otherwise, worker can exit before retrying the failed requests. + */ +#define UNDO_WORKER_LINGER_MS 20000 + +/* Flags set by signal handlers */ +static volatile sig_atomic_t got_SIGHUP = false; +static volatile sig_atomic_t got_SIGTERM = false; + +static TimestampTz last_xact_processed_at; + +typedef struct UndoApplyWorker +{ + /* Indicates if this slot is used or free. */ + bool in_use; + + /* Increased every time the slot is taken by new worker. */ + uint16 generation; + + /* Pointer to proc array. NULL if not running. */ + PGPROC *proc; + + /* Database id this worker is connected to. */ + Oid dbid; + + /* this tells whether worker is lingering. */ + bool lingering; + + /* + * This tells the undo worker from which undo worker queue it should start + * processing. + */ + UndoWorkerQueueType undo_worker_queue; +} UndoApplyWorker; + +UndoApplyWorker *MyUndoWorker = NULL; + +typedef struct UndoApplyCtxStruct +{ + /* Supervisor process. */ + pid_t launcher_pid; + + /* latch to wake up undo launcher. */ + Latch *undo_launcher_latch; + + /* Background workers. */ + UndoApplyWorker workers[FLEXIBLE_ARRAY_MEMBER]; +} UndoApplyCtxStruct; + +UndoApplyCtxStruct *UndoApplyCtx; + +static void UndoWorkerOnExit(int code, Datum arg); +static void UndoWorkerCleanup(UndoApplyWorker *worker); +static void UndoWorkerSetLingering(bool sleep); +static void UndoWorkerGetRequestInfo(UndoRequestInfo *urinfo); +static void UndoworkerSigtermHandler(SIGNAL_ARGS); + +/* + * Cleanup function for undo worker launcher. + * + * Called on undo worker launcher exit. + */ +static void +UndoLauncherOnExit(int code, Datum arg) +{ + UndoApplyCtx->launcher_pid = 0; + UndoApplyCtx->undo_launcher_latch = NULL; +} + +/* SIGTERM: set flag to exit at next convenient time */ +static void +UndoworkerSigtermHandler(SIGNAL_ARGS) +{ + got_SIGTERM = true; + + /* Waken anything waiting on the process latch */ + SetLatch(MyLatch); +} + +/* SIGHUP: set flag to reload configuration at next convenient time */ +static void +UndoLauncherSighup(SIGNAL_ARGS) +{ + int save_errno = errno; + + got_SIGHUP = true; + + /* Waken anything waiting on the process latch */ + SetLatch(MyLatch); + + errno = save_errno; +} + +/* + * Wait for a background worker to start up and attach to the shmem context. + * + * This is only needed for cleaning up the shared memory in case the worker + * fails to attach. + */ +static void +WaitForUndoWorkerAttach(UndoApplyWorker * worker, + uint16 generation, + BackgroundWorkerHandle *handle) +{ + BgwHandleStatus status; + int rc; + + for (;;) + { + pid_t pid; + + CHECK_FOR_INTERRUPTS(); + + LWLockAcquire(UndoWorkerLock, LW_SHARED); + + /* Worker either died or has started; no need to do anything. */ + if (!worker->in_use || worker->proc) + { + LWLockRelease(UndoWorkerLock); + return; + } + + LWLockRelease(UndoWorkerLock); + + /* Check if worker has died before attaching, and clean up after it. */ + status = GetBackgroundWorkerPid(handle, &pid); + + if (status == BGWH_STOPPED) + { + LWLockAcquire(UndoWorkerLock, LW_EXCLUSIVE); + /* Ensure that this was indeed the worker we waited for. */ + if (generation == worker->generation) + UndoWorkerCleanup(worker); + LWLockRelease(UndoWorkerLock); + return; + } + + /* + * We need timeout because we generally don't get notified via latch + * about the worker attach. But we don't expect to have to wait long. + */ + rc = WaitLatch(MyLatch, + WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, + 10L, WAIT_EVENT_BGWORKER_STARTUP); + + if (rc & WL_LATCH_SET) + ResetLatch(MyLatch); + } + + return; +} + +/* + * Attach to a slot. + */ +static void +UndoWorkerAttach(int slot) +{ + /* Block concurrent access. */ + LWLockAcquire(UndoWorkerLock, LW_SHARED); + + MyUndoWorker = &UndoApplyCtx->workers[slot]; + + if (!MyUndoWorker->in_use) + { + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("could not attach to undo worker slot"), + errdetail("slot %d is empty", slot))); + } + + if (MyUndoWorker->proc) + { + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("could not attach to undo worker slot"), + errdetail("slot %d is already used by another worker", + slot))); + } + + MyUndoWorker->proc = MyProc; + before_shmem_exit(UndoWorkerOnExit, (Datum) 0); + + LWLockRelease(UndoWorkerLock); +} + +/* + * Returns whether an undo worker is available. + */ +static bool +UndoWorkerIsAvailable(void) +{ + int i; + + LWLockAcquire(UndoWorkerLock, LW_SHARED); + + /* Search for attached workers. */ + for (i = 0; i < max_undo_workers; i++) + { + UndoApplyWorker *w = &UndoApplyCtx->workers[i]; + + if (!w->in_use) + { + LWLockRelease(UndoWorkerLock); + return true; + } + } + + LWLockRelease(UndoWorkerLock); + + return false; +} + +/* Sets the worker's lingering status. */ +static void +UndoWorkerSetLingering(bool sleep) +{ + /* Block concurrent access. */ + LWLockAcquire(UndoWorkerLock, LW_EXCLUSIVE); + + MyUndoWorker->lingering = sleep; + + LWLockRelease(UndoWorkerLock); +} + +/* Get the dbid and undo worker queue set by the undo launcher. */ +static void +UndoWorkerGetRequestInfo(UndoRequestInfo *urinfo) +{ + /* Block concurrent access. */ + LWLockAcquire(UndoWorkerLock, LW_SHARED); + + Assert(MyUndoWorker->in_use); + + urinfo->dbid = MyUndoWorker->dbid; + urinfo->undo_worker_queue = MyUndoWorker->undo_worker_queue; + + LWLockRelease(UndoWorkerLock); +} + +/* + * Start new undo apply background worker, if possible. + */ +static void +UndoWorkerLaunch(UndoRequestInfo *urinfo) +{ + BackgroundWorker bgw; + BackgroundWorkerHandle *bgw_handle; + uint16 generation; + int slot = 0; + UndoApplyWorker *worker = NULL; + + /* + * We need to do the modification of the shared memory under lock to have + * a consistent view. + */ + LWLockAcquire(UndoWorkerLock, LW_EXCLUSIVE); + + /* Find unused worker slot. */ + for (slot = 0; slot < max_undo_workers; slot++) + { + UndoApplyWorker *w = &UndoApplyCtx->workers[slot]; + + if (!w->in_use) + { + worker = w; + break; + } + } + + /* + * If there are no more free worker slots, inform user about it before + * exiting. + */ + if (worker == NULL) + { + LWLockRelease(UndoWorkerLock); + ereport(WARNING, + (errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED), + errmsg("out of undo worker slots"), + errhint("You might need to increase max_undo_workers."))); + return; + } + + /* Prepare the worker slot. */ + worker->in_use = true; + worker->proc = NULL; + worker->dbid = urinfo->dbid; + worker->lingering = false; + worker->undo_worker_queue = urinfo->undo_worker_queue; + worker->generation++; + + generation = worker->generation; + LWLockRelease(UndoWorkerLock); + + /* Register the new dynamic worker. */ + memset(&bgw, 0, sizeof(bgw)); + bgw.bgw_flags = BGWORKER_SHMEM_ACCESS | + BGWORKER_BACKEND_DATABASE_CONNECTION; + bgw.bgw_start_time = BgWorkerStart_RecoveryFinished; + snprintf(bgw.bgw_library_name, BGW_MAXLEN, "postgres"); + snprintf(bgw.bgw_function_name, BGW_MAXLEN, "UndoWorkerMain"); + snprintf(bgw.bgw_type, BGW_MAXLEN, "undo apply worker"); + snprintf(bgw.bgw_name, BGW_MAXLEN, "undo apply worker for database id %d", + worker->dbid); + + bgw.bgw_restart_time = BGW_NEVER_RESTART; + bgw.bgw_notify_pid = MyProcPid; + bgw.bgw_main_arg = Int32GetDatum(slot); + + if (!RegisterDynamicBackgroundWorker(&bgw, &bgw_handle)) + { + /* Failed to start worker, so clean up the worker slot. */ + LWLockAcquire(UndoWorkerLock, LW_EXCLUSIVE); + UndoWorkerCleanup(worker); + LWLockRelease(UndoWorkerLock); + + ereport(WARNING, + (errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED), + errmsg("out of undo worker slots"), + errhint("You might need to increase max_undo_workers."))); + + return; + } + + /* Now wait until it attaches. */ + WaitForUndoWorkerAttach(worker, generation, bgw_handle); + + return; +} + +/* + * Detach the worker (cleans up the worker info). + */ +static void +UndoWorkerDetach(void) +{ + /* Block concurrent access. */ + LWLockAcquire(UndoWorkerLock, LW_EXCLUSIVE); + + UndoWorkerCleanup(MyUndoWorker); + + LWLockRelease(UndoWorkerLock); +} + +/* + * Clean up worker info. + */ +static void +UndoWorkerCleanup(UndoApplyWorker *worker) +{ + Assert(LWLockHeldByMeInMode(UndoWorkerLock, LW_EXCLUSIVE)); + + worker->in_use = false; + worker->proc = NULL; + worker->dbid = InvalidOid; + worker->lingering = false; + worker->undo_worker_queue = InvalidUndoWorkerQueue; +} + +/* + * Cleanup function. + * + * Called on undo worker exit. + */ +static void +UndoWorkerOnExit(int code, Datum arg) +{ + UndoWorkerDetach(); +} + +/* + * Perform rollback request. We need to connect to the database for first + * request. This is required because we access system tables while performing + * undo actions. + */ +static void +UndoWorkerPerformRequest(UndoRequestInfo *urinfo) +{ + bool error = false; + + /* must be connected to the database. */ + Assert(MyDatabaseId != InvalidOid); + + StartTransactionCommand(); + PG_TRY(); + { + execute_undo_actions(urinfo->full_xid, urinfo->end_urec_ptr, + urinfo->start_urec_ptr, true); + } + PG_CATCH(); + { + error = true; + + /* + * Register the unprocessed request in an error queue, so that it can + * be processed in a timely fashion. If we fail to add the request in + * an error queue, then mark the entry status invalid. This request + * will be later added back to the queue by the discard worker. + */ + if (!InsertRequestIntoErrorUndoQueue(urinfo)) + RollbackHTMarkEntryInvalid(urinfo->full_xid, + urinfo->start_urec_ptr); + + /* Prevent interrupts while cleaning up. */ + HOLD_INTERRUPTS(); + + /* Send the error only to server log. */ + err_out_to_client(false); + EmitErrorReport(); + + /* + * Abort the transaction and continue processing pending undo requests. + */ + AbortOutOfAnyTransaction(); + FlushErrorState(); + + RESUME_INTERRUPTS(); + } + PG_END_TRY(); + + if (!error) + CommitTransactionCommand(); +} + +/* + * UndoLauncherShmemSize + * Compute space needed for undo launcher shared memory + */ +Size +UndoLauncherShmemSize(void) +{ + Size size; + + /* + * Need the fixed struct and the array of UndoWorker. + */ + size = sizeof(UndoApplyCtxStruct); + size = MAXALIGN(size); + size = add_size(size, mul_size(max_undo_workers, + sizeof(UndoApplyWorker))); + return size; +} + +/* + * UndoLauncherShmemInit + * Allocate and initialize undo worker launcher shared memory + */ +void +UndoLauncherShmemInit(void) +{ + bool found; + + UndoApplyCtx = (UndoApplyCtxStruct *) + ShmemInitStruct("Undo Worker Launcher Data", + UndoLauncherShmemSize(), + &found); + + if (!found) + { + int slot; + + memset(UndoApplyCtx, 0, UndoLauncherShmemSize()); + + /* Initialize memory for each worker slot. */ + for (slot = 0; slot < max_undo_workers; slot++) + { + UndoApplyWorker *worker = &UndoApplyCtx->workers[slot]; + + memset(worker, 0, sizeof(UndoApplyWorker)); + } + } +} + +/* + * UndoLauncherRegister + * Register a background worker running the undo worker launcher. + */ +void +UndoLauncherRegister(void) +{ + BackgroundWorker bgw; + + if (max_undo_workers == 0) + { + ereport(ERROR, + (errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED), + errmsg("cannot start undo launcher when max_undo_worker = 0"))); + return; + } + + memset(&bgw, 0, sizeof(bgw)); + bgw.bgw_flags = BGWORKER_SHMEM_ACCESS | + BGWORKER_BACKEND_DATABASE_CONNECTION; + bgw.bgw_start_time = BgWorkerStart_RecoveryFinished; + snprintf(bgw.bgw_library_name, BGW_MAXLEN, "postgres"); + snprintf(bgw.bgw_function_name, BGW_MAXLEN, "UndoLauncherMain"); + snprintf(bgw.bgw_name, BGW_MAXLEN, + "undo worker launcher"); + snprintf(bgw.bgw_type, BGW_MAXLEN, + "undo worker launcher"); + bgw.bgw_restart_time = 5; + bgw.bgw_notify_pid = 0; + bgw.bgw_main_arg = (Datum)0; + + RegisterBackgroundWorker(&bgw); +} + +/* + * Main loop for the undo worker launcher process. + */ +void +UndoLauncherMain(Datum main_arg) +{ + UndoRequestInfo urinfo; + + ereport(DEBUG1, + (errmsg("undo launcher started"))); + + before_shmem_exit(UndoLauncherOnExit, (Datum) 0); + + Assert(UndoApplyCtx->launcher_pid == 0); + UndoApplyCtx->launcher_pid = MyProcPid; + + /* Establish signal handlers. */ + pqsignal(SIGHUP, UndoLauncherSighup); + pqsignal(SIGTERM, UndoworkerSigtermHandler); + BackgroundWorkerUnblockSignals(); + + /* Establish connection to nailed catalogs. */ + BackgroundWorkerInitializeConnection(NULL, NULL, 0); + + /* + * Advertise our latch that undo request enqueuer can use to wake us up + * while we're sleeping. + */ + UndoApplyCtx->undo_launcher_latch = &MyProc->procLatch; + + /* Enter main loop */ + while (!got_SIGTERM) + { + int rc; + + CHECK_FOR_INTERRUPTS(); + + ResetUndoRequestInfo(&urinfo); + + /* + * Here, we have a race condition, which is that even though we have + * checked the availablity of worker before launching it, there is + * still a chance that we don't get worker by the time it tries to + * launch. We can avoid that race by doing it in lock, but it doesn't + * see worth as this is just a corner case. + */ + if (UndoGetWork(false, false, &urinfo, NULL) && + UndoWorkerIsAvailable()) + UndoWorkerLaunch(&urinfo); + + /* Wait for more work. */ + rc = WaitLatch(MyLatch, + WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, + DEFAULT_NAPTIME_PER_CYCLE, + WAIT_EVENT_UNDO_LAUNCHER_MAIN); + + if (rc & WL_LATCH_SET) + { + ResetLatch(MyLatch); + CHECK_FOR_INTERRUPTS(); + } + + if (got_SIGHUP) + { + got_SIGHUP = false; + ProcessConfigFile(PGC_SIGHUP); + } + } + + /* Normal exit from undo launcher main */ + ereport(LOG, + (errmsg("undo launcher shutting down"))); + proc_exit(0); +} + +/* + * UndoWorkerMain -- Main loop for the undo apply worker. + */ +void +UndoWorkerMain(Datum main_arg) +{ + UndoRequestInfo urinfo; + int worker_slot = DatumGetInt32(main_arg); + bool in_other_db; + bool found_work; + TimestampTz started_at; + + /* Setup signal handling */ + pqsignal(SIGTERM, UndoworkerSigtermHandler); + BackgroundWorkerUnblockSignals(); + + /* Attach to slot */ + UndoWorkerAttach(worker_slot); + + ResetUndoRequestInfo(&urinfo); + started_at = GetCurrentTimestamp(); + + /* + * Get the dbid where the worker should connect to and get the worker + * request queue from which the worker should start looking for an undo + * request. + */ + UndoWorkerGetRequestInfo(&urinfo); + + /* Connect to the requested database. */ + BackgroundWorkerInitializeConnectionByOid(urinfo.dbid, 0, 0); + + /* + * Set the undo worker request queue from which the undo worker should + * start looking for work. + */ + SetUndoWorkerQueueStart(urinfo.undo_worker_queue); + + /* + * Before attaching the worker, fetch and remove the undo request for + * which the undo launcher has launched this worker. This restricts the + * undo launcher from launching multiple workers for the same request. + * But, it's possible that the undo request has already been processed by + * other in-progress undo worker. In that case, we enter the undo worker + * main loop and fetch the next request. + */ + found_work = UndoGetWork(false, true, &urinfo, &in_other_db); + + if (found_work && !in_other_db) + { + /* We must have got the pending undo request. */ + Assert(FullTransactionIdIsValid(urinfo.full_xid)); + UndoWorkerPerformRequest(&urinfo); + last_xact_processed_at = GetCurrentTimestamp(); + } + + while (!got_SIGTERM) + { + int rc; + bool allow_peek; + + CHECK_FOR_INTERRUPTS(); + + /* + * We don't want to restart workers frequently, so allow to peek few + * entries ahead, if required. + */ + allow_peek = !TimestampDifferenceExceeds(started_at, + GetCurrentTimestamp(), + undo_worker_quantum_ms); + + found_work = UndoGetWork(allow_peek, true, &urinfo, &in_other_db); + + if (found_work && in_other_db) + { + proc_exit(0); + } + else if (found_work) + { + /* We must have got the pending undo request. */ + Assert(FullTransactionIdIsValid(urinfo.full_xid)); + UndoWorkerPerformRequest(&urinfo); + last_xact_processed_at = GetCurrentTimestamp(); + } + else + { + TimestampTz timeout = 0; + + timeout = TimestampTzPlusMilliseconds(last_xact_processed_at, + UNDO_WORKER_LINGER_MS); + + /* + * We don't need to linger if we have already spent + * UNDO_WORKER_LINGER_MS since last transaction has processed. + */ + if (timeout <= GetCurrentTimestamp()) + { + proc_exit(0); + } + + /* + * Update the shared state to reflect that this worker is + * lingering so that if there is new work request, the requester + * can wake us up. + */ + UndoWorkerSetLingering(true); + + /* Wait for more work. */ + rc = WaitLatch(MyLatch, + WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, + DEFAULT_NAPTIME_PER_CYCLE, + WAIT_EVENT_UNDO_WORKER_MAIN); + + /* reset the shared state. */ + UndoWorkerSetLingering(false); + + if (rc & WL_LATCH_SET) + { + ResetLatch(MyLatch); + CHECK_FOR_INTERRUPTS(); + } + + if (got_SIGHUP) + { + got_SIGHUP = false; + ProcessConfigFile(PGC_SIGHUP); + } + } + } + + /* Normal exit from undo worker main */ + proc_exit(0); +} + +/* + * Wake up undo worker so that undo requests can be processed in a timely + * fashion. + * + * We first try to wake up the lingering worker in the given database. If we + * found even one such worker, we are done. + * + * Next, we try to stop some worker which is lingering, but doesn't belong to + * the given database. We know that any worker which is lingering doesn't have + * any pending work, so it is fine to stop it when we know that there is going + * to be some work in the other database. + * + * Finally, we wakeup launcher so that it can either restart the worker we have + * stopped or find some other worker who can take up this request. + */ +void +WakeupUndoWorker(Oid dbid) +{ + int i; + + LWLockAcquire(UndoWorkerLock, LW_EXCLUSIVE); + + /* wake up lingering worker in the given database. */ + for (i = 0; i < max_undo_workers; i++) + { + UndoApplyWorker *w = &UndoApplyCtx->workers[i]; + + if (w->in_use && w->lingering && w->dbid == dbid) + { + SetLatch(&w->proc->procLatch); + + LWLockRelease(UndoWorkerLock); + return; + } + } + + /* + * Stop one of the lingering worker which is not processing the requests + * in the given database. + */ + for (i = 0; i < max_undo_workers; i++) + { + UndoApplyWorker *w = &UndoApplyCtx->workers[i]; + + if (w->in_use && w->lingering && w->dbid != dbid) + kill(w->proc->pid, SIGTERM); + } + + if (UndoApplyCtx->undo_launcher_latch) + SetLatch(UndoApplyCtx->undo_launcher_latch); + + LWLockRelease(UndoWorkerLock); + + return; +} diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 0c0ddd5..e774c55 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -24,6 +24,7 @@ #include "access/sysattr.h" #include "access/tableam.h" #include "access/tupconvert.h" +#include "access/undodiscard.h" #include "access/xact.h" #include "access/xlog.h" #include "catalog/catalog.h" @@ -14547,6 +14548,10 @@ PreCommit_on_commit_actions(void) case ONCOMMIT_DROP: oids_to_drop = lappend_oid(oids_to_drop, oc->relid); break; + case ONCOMMIT_TEMP_DISCARD: + /* Discard temp table undo logs for temp tables. */ + TempUndoDiscard(oc->relid); + break; } } diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c index b66b517..b3db6fb 100644 --- a/src/backend/postmaster/bgworker.c +++ b/src/backend/postmaster/bgworker.c @@ -15,7 +15,9 @@ #include <unistd.h> #include "libpq/pqsignal.h" +#include "access/discardworker.h" #include "access/parallel.h" +#include "access/undoworker.h" #include "miscadmin.h" #include "pgstat.h" #include "port/atomics.h" @@ -129,6 +131,15 @@ static const struct }, { "ApplyWorkerMain", ApplyWorkerMain + }, + { + "UndoLauncherMain", UndoLauncherMain + }, + { + "UndoWorkerMain", UndoWorkerMain + }, + { + "DiscardWorkerMain", DiscardWorkerMain } }; diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index d8dc0cc..4c906f6 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -3679,6 +3679,15 @@ pgstat_get_wait_activity(WaitEventActivity w) case WAIT_EVENT_WAL_WRITER_MAIN: event_name = "WalWriterMain"; break; + case WAIT_EVENT_UNDO_DISCARD_WORKER_MAIN: + event_name = "UndoDiscardWorkerMain"; + break; + case WAIT_EVENT_UNDO_LAUNCHER_MAIN: + event_name = "UndoLauncherMain"; + break; + case WAIT_EVENT_UNDO_WORKER_MAIN: + event_name = "UndoWorkerMain"; + break; /* no default case, so that compiler will warn */ } diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 3339804..6521efa 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -93,7 +93,9 @@ #include <pthread.h> #endif +#include "access/discardworker.h" #include "access/transam.h" +#include "access/undoworker.h" #include "access/xlog.h" #include "bootstrap/bootstrap.h" #include "catalog/pg_control.h" @@ -246,6 +248,8 @@ bool enable_bonjour = false; char *bonjour_name; bool restart_after_crash = true; +bool enable_undo_launcher = true; + /* PIDs of special child processes; 0 when not running */ static pid_t StartupPID = 0, BgWriterPID = 0, @@ -982,6 +986,13 @@ PostmasterMain(int argc, char *argv[]) */ ApplyLauncherRegister(); + /* Register the Undo worker launcher. */ + if (enable_undo_launcher) + UndoLauncherRegister(); + + /* Register the Undo Discard worker. */ + DiscardWorkerRegister(); + /* * process any libraries that should be preloaded at postmaster start */ diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c index 12c3249..56b5d08 100644 --- a/src/backend/storage/ipc/ipci.c +++ b/src/backend/storage/ipc/ipci.c @@ -22,6 +22,8 @@ #include "access/subtrans.h" #include "access/twophase.h" #include "access/undolog.h" +#include "access/undorequest.h" +#include "access/undoworker.h" #include "commands/async.h" #include "miscadmin.h" #include "pgstat.h" @@ -149,6 +151,8 @@ CreateSharedMemoryAndSemaphores(int port) size = add_size(size, BTreeShmemSize()); size = add_size(size, SyncScanShmemSize()); size = add_size(size, AsyncShmemSize()); + size = add_size(size, PendingUndoShmemSize()); + size = add_size(size, UndoLauncherShmemSize()); #ifdef EXEC_BACKEND size = add_size(size, ShmemBackendArraySize()); #endif @@ -220,6 +224,7 @@ CreateSharedMemoryAndSemaphores(int port) SUBTRANSShmemInit(); MultiXactShmemInit(); InitBufferPool(); + PendingUndoShmemInit(); /* * Set up lock manager @@ -258,6 +263,7 @@ CreateSharedMemoryAndSemaphores(int port) WalSndShmemInit(); WalRcvShmemInit(); ApplyLauncherShmemInit(); + UndoLauncherShmemInit(); /* * Set up other modules that need some shared memory space diff --git a/src/backend/storage/lmgr/lwlocknames.txt b/src/backend/storage/lmgr/lwlocknames.txt index 19e4f1f..1f65056 100644 --- a/src/backend/storage/lmgr/lwlocknames.txt +++ b/src/backend/storage/lmgr/lwlocknames.txt @@ -51,3 +51,4 @@ LogicalRepWorkerLock 43 CLogTruncationLock 44 UndoLogLock 45 RollbackRequestLock 46 +UndoWorkerLock 47 diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 884fa2a..61406cf 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -297,7 +297,9 @@ InitProcGlobal(void) ProcStructLock = (slock_t *) ShmemAlloc(sizeof(slock_t)); SpinLockInit(ProcStructLock); + pg_atomic_init_u64(&ProcGlobal->oldestFullXidHavingUnappliedUndo, 0); ProcGlobal->xactsHavingPendingUndo = 0; + ProcGlobal->rollbackHTInitialized = false; } /* diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index a7d1db5..8b4aa0c 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -33,6 +33,7 @@ #include "access/transam.h" #include "access/twophase.h" #include "access/undorequest.h" +#include "access/undoworker.h" #include "access/xact.h" #include "access/xlog_internal.h" #include "catalog/namespace.h" @@ -1955,6 +1956,17 @@ static struct config_bool ConfigureNamesBool[] = NULL, NULL, NULL }, + { + {"enable_undo_launcher", PGC_POSTMASTER, DEVELOPER_OPTIONS, + gettext_noop("Decides whether to launch an undo worker."), + NULL, + GUC_NOT_IN_SAMPLE + }, + &enable_undo_launcher, + true, + NULL, NULL, NULL + }, + /* End-of-list marker */ { {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL @@ -3031,6 +3043,16 @@ static struct config_int ConfigureNamesInt[] = }, { + {"max_undo_workers", PGC_POSTMASTER, RESOURCES_ASYNCHRONOUS, + gettext_noop("Maximum number of undo worker processes."), + NULL, + }, + &max_undo_workers, + 4, 0, MAX_BACKENDS, + NULL, NULL, NULL + }, + + { {"autovacuum_work_mem", PGC_SIGHUP, RESOURCES_MEM, gettext_noop("Sets the maximum memory to be used by each autovacuum worker process."), NULL, diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index 592f6e1..e86507c 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -612,6 +612,7 @@ # requests are pushed to undo workers #pending_undo_queue_size = 1024 # size of queue used to register undo # requests +#max_undo_workers = 4 # maximum undo workers #------------------------------------------------------------------------------ # CLIENT CONNECTION DEFAULTS diff --git a/src/include/access/discardworker.h b/src/include/access/discardworker.h new file mode 100644 index 0000000..5b065bf --- /dev/null +++ b/src/include/access/discardworker.h @@ -0,0 +1,20 @@ +/*------------------------------------------------------------------------- + * + * discardworker.h + * Exports from access/undo/discardworker.c. + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/discardworker.h + * + *------------------------------------------------------------------------- + */ +#ifndef _DISCARDWORKER_H +#define _DISCARDWORKER_H + +extern void DiscardWorkerRegister(void); +extern void DiscardWorkerMain(Datum main_arg) pg_attribute_noreturn(); +extern bool IsDiscardProcess(void); + +#endif /* _DISCARDWORKER_H */ diff --git a/src/include/access/transam.h b/src/include/access/transam.h index 7796f72..e68e743 100644 --- a/src/include/access/transam.h +++ b/src/include/access/transam.h @@ -73,6 +73,16 @@ FullTransactionIdFromEpochAndXid(uint32 epoch, TransactionId xid) return result; } +static inline FullTransactionId +FullTransactionIdFromU64(uint64 fxid) +{ + FullTransactionId result; + + result.value = fxid; + + return result; +} + /* advance a transaction ID variable, handling wraparound correctly */ #define TransactionIdAdvance(dest) \ do { \ diff --git a/src/include/access/undodiscard.h b/src/include/access/undodiscard.h new file mode 100644 index 0000000..282afc0 --- /dev/null +++ b/src/include/access/undodiscard.h @@ -0,0 +1,26 @@ +/*------------------------------------------------------------------------- + * + * undoinsert.h + * undo discard definitions + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/undodiscard.h + * + *------------------------------------------------------------------------- + */ +#ifndef UNDODISCARD_H +#define UNDODISCARD_H + +#include "access/undolog.h" +#include "access/xlogdefs.h" +#include "catalog/pg_class.h" +#include "storage/lwlock.h" + +extern void UndoDiscard(TransactionId xmin, bool *hibernate); +extern void UndoLogDiscardAll(void); +extern void TempUndoDiscard(UndoLogNumber); +extern void UndoLogProcess(void); + +#endif /* UNDODISCARD_H */ diff --git a/src/include/access/undolog.h b/src/include/access/undolog.h index 7ec4cb0..b19b931 100644 --- a/src/include/access/undolog.h +++ b/src/include/access/undolog.h @@ -279,6 +279,19 @@ typedef struct UndoLogAllocContext /* * The in-memory control object for an undo log. We have a fixed-sized array * of these. + * + * The following two locks are used to manage the discard process + * discard_lock - should be acquired for undo read to protect it from discard and + * discard worker will acquire this lock to update oldest_data. + * + * discard_update_lock - This lock will be acquired in exclusive mode by discard + * worker during the discard process and in shared mode to update the + * next_urp in previous transaction's start header. + * + * Two different locks are used so that the readers are not blocked during the + * actual discard but only during the update of shared memory variable which + * influences the visibility decision but the updaters need to be blocked for + * the entire discard process to ensure proper ordering of WAL records. */ typedef struct UndoLogSlot { diff --git a/src/include/access/undoworker.h b/src/include/access/undoworker.h new file mode 100644 index 0000000..1bdc31f --- /dev/null +++ b/src/include/access/undoworker.h @@ -0,0 +1,29 @@ +/*------------------------------------------------------------------------- + * + * undoworker.h + * Exports from undoworker.c. + * + * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/undoworker.h + * + *------------------------------------------------------------------------- + */ +#ifndef _UNDOWORKER_H +#define _UNDOWORKER_H + +/* GUC options */ +extern int max_undo_workers; + +/* undo worker sleep time between rounds */ +extern int UndoWorkerDelay; + +extern Size UndoLauncherShmemSize(void); +extern void UndoLauncherShmemInit(void); +extern void UndoLauncherRegister(void); +extern void UndoLauncherMain(Datum main_arg); +extern void UndoWorkerMain(Datum main_arg) pg_attribute_noreturn(); +extern void WakeupUndoWorker(Oid dbid); + +#endif /* _UNDOWORKER_H */ diff --git a/src/include/catalog/pg_control.h b/src/include/catalog/pg_control.h index ff98d9e..babcc6b 100644 --- a/src/include/catalog/pg_control.h +++ b/src/include/catalog/pg_control.h @@ -61,6 +61,15 @@ typedef struct CheckPoint * set to InvalidTransactionId. */ TransactionId oldestActiveXid; + + /* + * Oldest full transaction id which is having unapplied undo. We include + * this value in the checkpoint record so that whenever server re-starts + * we can use this to initialize the server-wide value for same variable. + * Any Xid prior to this should be all-visible, so if this is not set, + * then the scans might try to fetch undo which can suck the performance. + */ + FullTransactionId oldestFullXidHavingUnappliedUndo; } CheckPoint; /* XLOG info values for XLOG rmgr */ diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h index 860a84d..cca575b 100644 --- a/src/include/nodes/primnodes.h +++ b/src/include/nodes/primnodes.h @@ -49,7 +49,8 @@ typedef enum OnCommitAction ONCOMMIT_NOOP, /* No ON COMMIT clause (do nothing) */ ONCOMMIT_PRESERVE_ROWS, /* ON COMMIT PRESERVE ROWS (do nothing) */ ONCOMMIT_DELETE_ROWS, /* ON COMMIT DELETE ROWS */ - ONCOMMIT_DROP /* ON COMMIT DROP */ + ONCOMMIT_DROP, /* ON COMMIT DROP */ + ONCOMMIT_TEMP_DISCARD /* ON COMMIT discard temp table undo logs */ } OnCommitAction; /* diff --git a/src/include/pgstat.h b/src/include/pgstat.h index 2fff673..f9dc0bb 100644 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@ -785,7 +785,10 @@ typedef enum WAIT_EVENT_SYSLOGGER_MAIN, WAIT_EVENT_WAL_RECEIVER_MAIN, WAIT_EVENT_WAL_SENDER_MAIN, - WAIT_EVENT_WAL_WRITER_MAIN + WAIT_EVENT_WAL_WRITER_MAIN, + WAIT_EVENT_UNDO_DISCARD_WORKER_MAIN, + WAIT_EVENT_UNDO_LAUNCHER_MAIN, + WAIT_EVENT_UNDO_WORKER_MAIN } WaitEventActivity; /* ---------- diff --git a/src/include/postmaster/postmaster.h b/src/include/postmaster/postmaster.h index b692d8b..b9af96d 100644 --- a/src/include/postmaster/postmaster.h +++ b/src/include/postmaster/postmaster.h @@ -29,6 +29,7 @@ extern bool log_hostname; extern bool enable_bonjour; extern char *bonjour_name; extern bool restart_after_crash; +extern bool enable_undo_launcher; #ifdef WIN32 extern HANDLE PostmasterHandle; diff --git a/src/include/storage/lwlock.h b/src/include/storage/lwlock.h index 4abb344..b220a05 100644 --- a/src/include/storage/lwlock.h +++ b/src/include/storage/lwlock.h @@ -223,6 +223,7 @@ typedef enum BuiltinTrancheIds LWTRANCHE_UNDOLOG, LWTRANCHE_UNDODISCARD, LWTRANCHE_REWIND, + LWTRANCHE_DISCARD_UPDATE, LWTRANCHE_FIRST_USER_DEFINED, } BuiltinTrancheIds; diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 824f6bf..bcee3e1 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -272,8 +272,12 @@ typedef struct PROC_HDR int startupProcPid; /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ int startupBufferPinWaitBufId; + /* Oldest transaction id which is having undo. */ + pg_atomic_uint64 oldestFullXidHavingUnappliedUndo; /* Number of aborted transactions with pending undo actions. */ int xactsHavingPendingUndo; + /* Whether the rollback hash table is initialized after the startup? */ + bool rollbackHTInitialized; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; diff --git a/src/include/storage/procarray.h b/src/include/storage/procarray.h index da8b672..1d12994 100644 --- a/src/include/storage/procarray.h +++ b/src/include/storage/procarray.h @@ -27,6 +27,8 @@ * to avoid forcing to include proc.h when including procarray.h. So if you modify * PROC_XXX flags, you need to modify these flags. */ +#define PROCARRAY_AUTOVACUUM_FLAG 0x01 /* currently running + * autovacuum */ #define PROCARRAY_VACUUM_FLAG 0x02 /* currently running lazy * vacuum */ #define PROCARRAY_ANALYZE_FLAG 0x04 /* currently running @@ -41,7 +43,8 @@ * PGXACT->vacuumFlags. Other flags are used for different purposes and * have no corresponding PROC flag equivalent. */ -#define PROCARRAY_PROC_FLAGS_MASK (PROCARRAY_VACUUM_FLAG | \ +#define PROCARRAY_PROC_FLAGS_MASK (PROCARRAY_AUTOVACUUM_FLAG | \ + PROCARRAY_VACUUM_FLAG | \ PROCARRAY_ANALYZE_FLAG | \ PROCARRAY_LOGICAL_DECODING_FLAG) @@ -50,6 +53,8 @@ #define PROCARRAY_FLAGS_DEFAULT PROCARRAY_LOGICAL_DECODING_FLAG /* Ignore vacuum backends */ #define PROCARRAY_FLAGS_VACUUM PROCARRAY_FLAGS_DEFAULT | PROCARRAY_VACUUM_FLAG +/* Ignore autovacuum worker and backends running vacuum */ +#define PROCARRAY_FLAGS_AUTOVACUUM PROCARRAY_FLAGS_DEFAULT | PROCARRAY_AUTOVACUUM_FLAG /* Ignore analyze backends */ #define PROCARRAY_FLAGS_ANALYZE PROCARRAY_FLAGS_DEFAULT | PROCARRAY_ANALYZE_FLAG /* Ignore both vacuum and analyze backends */ diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out index a1c90eb..6034c5e 100644 --- a/src/test/regress/expected/sysviews.out +++ b/src/test/regress/expected/sysviews.out @@ -89,7 +89,8 @@ select name, setting from pg_settings where name like 'enable%'; enable_seqscan | on enable_sort | on enable_tidscan | on -(17 rows) + enable_undo_launcher | on +(18 rows) -- Test that the pg_timezone_names and pg_timezone_abbrevs views are -- more-or-less working. We can't test their contents in any great detail -- 1.8.3.1 ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v1 4/4] Extra tests @ 2025-08-31 09:10 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-08-31 09:10 UTC (permalink / raw) Add more tests for trenary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fae..78d1d84ed9a 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- trenary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6fc..19826e50e6d 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + trenary option_trenary1; + trenary option_trenary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_trenary_reloption(di_relopt_kind, "option_trenary1", + "First trenary option for dummy_index_am", + TRENARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_trenary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_trenary1); + + add_trenary_reloption(di_relopt_kind, "option_trenary2", + "Second trenary option for dummy_index_am", + TRENARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_trenary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TRENARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_trenary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb75..bcf164f5bf7 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_trenary1=true + option_trenary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_trenary1=false + option_trenary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ERROR: invalid value for trenary option "option_trenary1": 4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ERROR: invalid value for trenary option "option_trenary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ERROR: invalid value for trenary option "option_trenary1": val4 +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ERROR: invalid value for trenary option "option_trenary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_trenary1=1 + option_trenary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6a..7e752b12d16 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_trenary1, + option_trenary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_trenary1 = false); +ALTER INDEX dummy_test_idx SET (option_trenary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Trenary +ALTER INDEX dummy_test_idx SET (option_trenary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_trenary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_trenary1 = 'do_not_know_yet'); -- error. Valid for trenary2 not for trenary1 +ALTER INDEX dummy_test_idx SET (option_trenary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_trenary1); +ALTER INDEX dummy_test_idx RESET (option_trenary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index e32431ca067..54b3424ef2b 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index 051142eed5f..1971d460672 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) trenary options +-- Tests for trenary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart6784952.tM3a2QDmDi-- --nextPart6187903.UjTJXf6HLC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi0gCMACgkQPMbfuIHA Gpi3Dgf/dQxIJ7WM8rL4szT+d+7gCw1BUzA7H4SkLtGM8E+akUvbjt6lFpCKN7fP dHWTY7NeHsLy8hXB7Z+P4edaHAqNQ7pXtESuC0jBB1Ta5r9f0mUz/tNvyaoj1YPV SES411gQwABIJ/ZXoqrcAHgmJoyAKZcFWU9HBAhJyL3Da/o7L86wgro4a6ov7cgP 1mJa6WjH1qf1v4PPrZYxLMmU5v3uacNDFowNsQ8+uHs+slUWjkw4VYatdReWla0a 4qBnMaht1Xky3f55YfB7Gx28CBUUPMREUVKFOrcopq95kZ9WASoTJfU9Y80IDPWb KVcJvYDk5TEL1t48GpFkjZbL9od51w== =yrfm -----END PGP SIGNATURE----- --nextPart6187903.UjTJXf6HLC-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2a 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart4155600.3ZeAukHxDK-- --nextPart4961315.687JKscXgg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmjGgZ4ACgkQPMbfuIHA GpgHFgf/dwjUCCKw4wFDpFssAUVnClknwo+DYhgbni6DfBlLM8bjB0CWwZsNGUEv dGueFJY9q4+3YPon9sqb1KIqBZDtLaGj69U+K+ZtLkjOc8WV4VOmUyZuuSaZh9lw JFM+d8RZNTemYQ5Nc82YuF+4MDiiM3480vhAr412LMRd/6P4dk+vKDL2kopodhB+ xbZYtARolC/bZaMTla68L/4X5qidfsd4zd+QZjf8JXwv1mq2MZCuHvsuMMViWp3Z Hf7r4bj407BjEYH/UNpE70iWa65xDCHpRSOYJ6QKFxRnAEYBim6u3G7t85jnHz7O mVGvRJLeVMgh2l6TCxG7fSJGwh/Qrg== =Agrf -----END PGP SIGNATURE----- --nextPart4961315.687JKscXgg-- ^ permalink raw reply [nested|flat] 811+ messages in thread
* [PATCH v2 4/4] Extra tests @ 2025-09-04 16:28 Nikolay Shaplov <[email protected]> 0 siblings, 0 replies; 811+ messages in thread From: Nikolay Shaplov @ 2025-09-04 16:28 UTC (permalink / raw) Add more tests for ternary reloptions in dummy_index_am module --- src/test/modules/dummy_index_am/README | 1 + .../modules/dummy_index_am/dummy_index_am.c | 36 +++++++++++++----- .../dummy_index_am/expected/reloptions.out | 38 +++++++++++++++++-- .../modules/dummy_index_am/sql/reloptions.sql | 16 ++++++++ src/test/regress/expected/reloptions.out | 4 +- src/test/regress/sql/reloptions.sql | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/test/modules/dummy_index_am/README b/src/test/modules/dummy_index_am/README index 61510f02fa..d80aff0db1 100644 --- a/src/test/modules/dummy_index_am/README +++ b/src/test/modules/dummy_index_am/README @@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple. This includes tests for all relation option types: - boolean +- ternary - enum - integer - real diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c index 94ef639b6f..bf8446ddc6 100644 --- a/src/test/modules/dummy_index_am/dummy_index_am.c +++ b/src/test/modules/dummy_index_am/dummy_index_am.c @@ -22,7 +22,7 @@ PG_MODULE_MAGIC; /* parse table for fillRelOptions */ -static relopt_parse_elt di_relopt_tab[6]; +static relopt_parse_elt di_relopt_tab[8]; /* Kind of relation options for dummy index */ static relopt_kind di_relopt_kind; @@ -40,6 +40,8 @@ typedef struct DummyIndexOptions int option_int; double option_real; bool option_bool; + ternary option_ternary1; + ternary option_ternary2; DummyAmEnum option_enum; int option_string_val_offset; int option_string_null_offset; @@ -96,23 +98,37 @@ create_reloptions_table(void) di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL; di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool); + add_ternary_reloption(di_relopt_kind, "option_ternary1", + "First ternary option for dummy_index_am", + TERNARY_UNSET, NULL, AccessExclusiveLock); + di_relopt_tab[3].optname = "option_ternary1"; + di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1); + + add_ternary_reloption(di_relopt_kind, "option_ternary2", + "Second ternary option for dummy_index_am", + TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock); + di_relopt_tab[4].optname = "option_ternary2"; + di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY; + di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2); + add_enum_reloption(di_relopt_kind, "option_enum", "Enum option for dummy_index_am", dummyAmEnumValues, DUMMY_AM_ENUM_ONE, "Valid values are \"one\" and \"two\".", AccessExclusiveLock); - di_relopt_tab[3].optname = "option_enum"; - di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM; - di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum); + di_relopt_tab[5].optname = "option_enum"; + di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM; + di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum); add_string_reloption(di_relopt_kind, "option_string_val", "String option for dummy_index_am with non-NULL default", "DefaultValue", &validate_string_option, AccessExclusiveLock); - di_relopt_tab[4].optname = "option_string_val"; - di_relopt_tab[4].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[4].offset = offsetof(DummyIndexOptions, + di_relopt_tab[6].optname = "option_string_val"; + di_relopt_tab[6].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[6].offset = offsetof(DummyIndexOptions, option_string_val_offset); /* @@ -123,9 +139,9 @@ create_reloptions_table(void) NULL, /* description */ NULL, &validate_string_option, AccessExclusiveLock); - di_relopt_tab[5].optname = "option_string_null"; - di_relopt_tab[5].opttype = RELOPT_TYPE_STRING; - di_relopt_tab[5].offset = offsetof(DummyIndexOptions, + di_relopt_tab[7].optname = "option_string_null"; + di_relopt_tab[7].opttype = RELOPT_TYPE_STRING; + di_relopt_tab[7].offset = offsetof(DummyIndexOptions, option_string_null_offset); } diff --git a/src/test/modules/dummy_index_am/expected/reloptions.out b/src/test/modules/dummy_index_am/expected/reloptions.out index c873a80bb7..ad1b2ea639 100644 --- a/src/test/modules/dummy_index_am/expected/reloptions.out +++ b/src/test/modules/dummy_index_am/expected/reloptions.out @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; unnest ------------------------ option_bool=false + option_ternary1=true + option_ternary2=off option_int=5 option_real=3.1 option_enum=two option_string_val=null option_string_null=val -(6 rows) +(8 rows) -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three'); ERROR: invalid value for enum option "option_enum": three DETAIL: Valid values are "one" and "two". SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; - unnest -------------------------- + unnest +--------------------------------- option_int=10 option_bool=true + option_ternary1=false + option_ternary2=do_not_know_yet option_real=3.2 option_string_val=val2 option_string_null=null option_enum=one -(6 rows) +(8 rows) -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; (1 row) ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ERROR: invalid value for ternary option "option_ternary1": 4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ERROR: invalid value for ternary option "option_ternary1": 3.4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ERROR: invalid value for ternary option "option_ternary1": val4 +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; + unnest +--------------------------------- + option_ternary1=1 + option_ternary2=do_not_know_yet +(2 rows) + +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/modules/dummy_index_am/sql/reloptions.sql b/src/test/modules/dummy_index_am/sql/reloptions.sql index 6749d763e6..123540905a 100644 --- a/src/test/modules/dummy_index_am/sql/reloptions.sql +++ b/src/test/modules/dummy_index_am/sql/reloptions.sql @@ -18,6 +18,8 @@ SET client_min_messages TO 'notice'; CREATE INDEX dummy_test_idx ON dummy_test_tab USING dummy_index_am (i) WITH ( option_bool = false, + option_ternary1, + option_ternary2 = off, option_int = 5, option_real = 3.1, option_enum = 'two', @@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. SET ALTER INDEX dummy_test_idx SET (option_int = 10); ALTER INDEX dummy_test_idx SET (option_bool = true); +ALTER INDEX dummy_test_idx SET (option_ternary1 = false); +ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET); ALTER INDEX dummy_test_idx SET (option_real = 3.2); ALTER INDEX dummy_test_idx SET (option_string_val = 'val2'); ALTER INDEX dummy_test_idx SET (option_string_null = NULL); @@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; -- ALTER INDEX .. RESET ALTER INDEX dummy_test_idx RESET (option_int); ALTER INDEX dummy_test_idx RESET (option_bool); +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); ALTER INDEX dummy_test_idx RESET (option_real); ALTER INDEX dummy_test_idx RESET (option_enum); ALTER INDEX dummy_test_idx RESET (option_string_val); @@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; ALTER INDEX dummy_test_idx RESET (option_bool); +-- Ternary +ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true +ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error +ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1 +ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok +SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx'; +ALTER INDEX dummy_test_idx RESET (option_ternary1); +ALTER INDEX dummy_test_idx RESET (option_ternary2); -- Float ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok ALTER INDEX dummy_test_idx SET (option_real = true); -- error diff --git a/src/test/regress/expected/reloptions.out b/src/test/regress/expected/reloptions.out index 1c99f79ab0..6e65cd5c3d 100644 --- a/src/test/regress/expected/reloptions.out +++ b/src/test/regress/expected/reloptions.out @@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {fillfactor=13,autovacuum_enabled=false} (1 row) --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate); @@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; {vacuum_truncate=fals} (1 row) --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; diff --git a/src/test/regress/sql/reloptions.sql b/src/test/regress/sql/reloptions.sql index f5980dafcb..c99673db9e 100644 --- a/src/test/regress/sql/reloptions.sql +++ b/src/test/regress/sql/reloptions.sql @@ -59,7 +59,7 @@ UPDATE pg_class ALTER TABLE reloptions_test RESET (illegal_option); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- Tests for future (FIXME) ternary options +-- Tests for ternary options -- behave as boolean option: accept unassigned name and truncated value DROP TABLE reloptions_test; @@ -70,7 +70,7 @@ DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; --- preferred "true" alias is used when storing +-- preferred "true" alias is stored in pg_class DROP TABLE reloptions_test; CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on); SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass; -- 2.39.2 --nextPart5129932.5fSG56mABF-- --nextPart7913091.MhkbZ0Pkbq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE+sk3ebqQKlezKOi8PMbfuIHAGpgFAmi5xzQACgkQPMbfuIHA GpgVIAf/XPjp6PMbvLKQNz7lPTc3R8PRBXQG4MIj5C5xa3fM5s5uIq/aMYD6CL2g PycNUWsA/HumkH6h64TYT2JL3oeo2cXO9BU66Dm/wDJqz95eR6KANzfS2UC0qpyf Qab+JdontqQITiXrvHX4IB9RZRndkJa+OKWHxvzY2oToizXkbPwEDFcQR3+kUPAu BEl6f6BmJzd9tJAJz5wXINV3TTRe++dmtHkNesmq8c8P4R62PhBkjjGynczCjnke z319jJS71lEjNsKVvCkzkjpVNTGO7w33rIJQGscW+PUNGhUVB4qDqxfHPGSZS1Sb fU0Sv+UciXMopbvtezVtK30GBezX8Q== =RxGQ -----END PGP SIGNATURE----- --nextPart7913091.MhkbZ0Pkbq-- ^ permalink raw reply [nested|flat] 811+ messages in thread
end of thread, other threads:[~2025-09-04 16:28 UTC | newest] Thread overview: 811+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2019-08-09 08:21 Re: POC: Cleaning up orphaned files using undo logs Amit Kapila <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-08-31 09:10 [PATCH v1 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2a 4/4] Extra tests Nikolay Shaplov <[email protected]> 2025-09-04 16:28 [PATCH v2 4/4] Extra tests Nikolay Shaplov <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox